refactor(anilist): use closure callbacks

This commit is contained in:
Lemmy
2026-07-24 22:38:38 -04:00
parent 5579b20b51
commit 24cab9daa7
2 changed files with 14 additions and 21 deletions
+12 -19
View File
@@ -42,7 +42,6 @@ local function coverLoadingSet()
return set
end
local env = getfenv()
local function tr(key, subst)
return noctalia.tr("panel." .. key, subst)
@@ -62,12 +61,6 @@ local function sendCommand(action, values)
noctalia.state.set("anilist_command", command)
end
local function rowCallback(prefix, mediaId, fn)
local name = prefix .. "_" .. tostring(mediaId)
env[name] = fn
return name
end
local function resetListView()
visibleRowLimit = INITIAL_VISIBLE_ROWS
lastCoverPriorityKey = ""
@@ -218,12 +211,12 @@ local function filterButton(key, label, filter)
key = "filter-" .. key,
text = label,
variant = if active then "primary" else "ghost",
onClick = rowCallback("onFilter", key, function()
onClick = function()
statusFilter = filter
resetListView()
dirty = true
render()
end),
end,
})
end
@@ -421,9 +414,9 @@ local function renderCover(entry, loadingSet)
radius = 6,
fit = "cover",
tooltip = tr("cover_preview"),
onClick = rowCallback("onCover", mediaId, function()
onClick = function()
openCoverPreview(entry)
end),
end,
})
end
@@ -482,33 +475,33 @@ local function renderEntryRow(entry, index, loadingSet)
glyph = "minus",
variant = "ghost",
tooltip = tr("decrement"),
onClick = canDecrement and rowCallback("onDec", mediaId, function()
onClick = canDecrement and function()
sendCommand("decrement", { mediaId = mediaId })
end) or "onNoop",
end or "onNoop",
}))
table.insert(rowChildren, ui.button({
glyph = "plus",
variant = "ghost",
tooltip = tr("increment"),
onClick = canIncrement and rowCallback("onInc", mediaId, function()
onClick = canIncrement and function()
sendCommand("increment", { mediaId = mediaId })
end) or "onNoop",
end or "onNoop",
}))
table.insert(rowChildren, ui.button({
glyph = if isComplete then "check" else "circle-check",
variant = if isComplete then "primary" else "ghost",
tooltip = tr("mark_complete"),
onClick = snapshot.busy and "onNoop" or rowCallback("onDone", mediaId, function()
onClick = snapshot.busy and "onNoop" or function()
sendCommand("complete", { mediaId = mediaId })
end),
end,
}))
table.insert(rowChildren, ui.button({
glyph = "external-link",
variant = "ghost",
tooltip = tr("open_anilist"),
onClick = rowCallback("onOpen", mediaId, function()
onClick = function()
sendCommand("open_media", { mediaId = mediaId, mediaType = entry.mediaType })
end),
end,
}))
return ui.row({
+2 -2
View File
@@ -1,7 +1,7 @@
id = "cleboost/anilist"
name = "AniList (UNOFFICIAL)"
version = "1.0.0"
plugin_api = 3
version = "1.0.1"
plugin_api = 9
author = "cleboost"
license = "MIT"
icon = "device-tv"