diff --git a/components/TodoChecklister.lua b/components/TodoChecklister.lua index 0aa01c8..d9e1fd2 100644 --- a/components/TodoChecklister.lua +++ b/components/TodoChecklister.lua @@ -49,11 +49,10 @@ end -------------------------------------- function TodoChecklisterFrame:OnUpdate() local scrollFrame = TodoItemsScrollFrame - local list = TodoChecklisterDB or {} - if (scrollFrame and scrollFrame.buttons and list) then + if (scrollFrame and scrollFrame.buttons and TodoChecklisterDB) then local offset = HybridScrollFrame_GetOffset(scrollFrame) - if (#list > 0) then + if (#TodoChecklisterDB > 0) then self.frame.Background.BlankText:SetText('') else self.frame.Background.BlankText:SetText('Oh no! \r\n You have no items on your list \r\n\r\n Start by typing them in the box above \r\n\r\n =)') @@ -63,8 +62,8 @@ function TodoChecklisterFrame:OnUpdate() local idx = i + offset local button = scrollFrame.buttons[i] - if ( idx <= #list ) then - local todoItem = list[idx] + if ( idx <= #TodoChecklisterDB ) then + local todoItem = TodoChecklisterDB[idx] button.todoItem = todoItem -- Update button values @@ -85,7 +84,7 @@ function TodoChecklisterFrame:OnUpdate() end end - HybridScrollFrame_Update(scrollFrame, (scrollFrame.buttons[1]:GetHeight()) * #list, scrollFrame:GetHeight()) + HybridScrollFrame_Update(scrollFrame, (scrollFrame.buttons[1]:GetHeight()) * #TodoChecklisterDB, scrollFrame:GetHeight()) end end diff --git a/constants.lua b/constants.lua index 1622cae..0442ba4 100644 --- a/constants.lua +++ b/constants.lua @@ -6,6 +6,10 @@ core.Constants = {}; -- adds Config table to addon namespace local Constants = core.Constants; +if (not TodoChecklisterDB) then + TodoChecklisterDB = {} +end + -------------------------------------- -- Defaults (usually a database!) -------------------------------------- diff --git a/init.lua b/init.lua index 967c3a4..92ba013 100644 --- a/init.lua +++ b/init.lua @@ -3,16 +3,12 @@ local addonName, core = ...; -- Namespace -- WARNING: self keyword automatically becomes events frame! function core:Init(event, name) if (name ~= addonName) then return end - - if (not TodoChecklisterDB) then - TodoChecklisterDB = {} - end core.Debug:Init(); core.Chat:Init(); core.MinimapIcon:Init(); - if (#TodoChecklisterDB > 0) then + if (TodoChecklisterDB and #TodoChecklisterDB > 0) then local completedList = core.TableUtils:Filter(TodoChecklisterDB, function(x) return x.isChecked == true end) local notList = core.TableUtils:Filter(TodoChecklisterDB, function(x) return x.isChecked == false end)