refactor(anilist): use closure callbacks
This commit is contained in:
+12
-19
@@ -42,7 +42,6 @@ local function coverLoadingSet()
|
|||||||
return set
|
return set
|
||||||
end
|
end
|
||||||
|
|
||||||
local env = getfenv()
|
|
||||||
|
|
||||||
local function tr(key, subst)
|
local function tr(key, subst)
|
||||||
return noctalia.tr("panel." .. key, subst)
|
return noctalia.tr("panel." .. key, subst)
|
||||||
@@ -62,12 +61,6 @@ local function sendCommand(action, values)
|
|||||||
noctalia.state.set("anilist_command", command)
|
noctalia.state.set("anilist_command", command)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function rowCallback(prefix, mediaId, fn)
|
|
||||||
local name = prefix .. "_" .. tostring(mediaId)
|
|
||||||
env[name] = fn
|
|
||||||
return name
|
|
||||||
end
|
|
||||||
|
|
||||||
local function resetListView()
|
local function resetListView()
|
||||||
visibleRowLimit = INITIAL_VISIBLE_ROWS
|
visibleRowLimit = INITIAL_VISIBLE_ROWS
|
||||||
lastCoverPriorityKey = ""
|
lastCoverPriorityKey = ""
|
||||||
@@ -218,12 +211,12 @@ local function filterButton(key, label, filter)
|
|||||||
key = "filter-" .. key,
|
key = "filter-" .. key,
|
||||||
text = label,
|
text = label,
|
||||||
variant = if active then "primary" else "ghost",
|
variant = if active then "primary" else "ghost",
|
||||||
onClick = rowCallback("onFilter", key, function()
|
onClick = function()
|
||||||
statusFilter = filter
|
statusFilter = filter
|
||||||
resetListView()
|
resetListView()
|
||||||
dirty = true
|
dirty = true
|
||||||
render()
|
render()
|
||||||
end),
|
end,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -421,9 +414,9 @@ local function renderCover(entry, loadingSet)
|
|||||||
radius = 6,
|
radius = 6,
|
||||||
fit = "cover",
|
fit = "cover",
|
||||||
tooltip = tr("cover_preview"),
|
tooltip = tr("cover_preview"),
|
||||||
onClick = rowCallback("onCover", mediaId, function()
|
onClick = function()
|
||||||
openCoverPreview(entry)
|
openCoverPreview(entry)
|
||||||
end),
|
end,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -482,33 +475,33 @@ local function renderEntryRow(entry, index, loadingSet)
|
|||||||
glyph = "minus",
|
glyph = "minus",
|
||||||
variant = "ghost",
|
variant = "ghost",
|
||||||
tooltip = tr("decrement"),
|
tooltip = tr("decrement"),
|
||||||
onClick = canDecrement and rowCallback("onDec", mediaId, function()
|
onClick = canDecrement and function()
|
||||||
sendCommand("decrement", { mediaId = mediaId })
|
sendCommand("decrement", { mediaId = mediaId })
|
||||||
end) or "onNoop",
|
end or "onNoop",
|
||||||
}))
|
}))
|
||||||
table.insert(rowChildren, ui.button({
|
table.insert(rowChildren, ui.button({
|
||||||
glyph = "plus",
|
glyph = "plus",
|
||||||
variant = "ghost",
|
variant = "ghost",
|
||||||
tooltip = tr("increment"),
|
tooltip = tr("increment"),
|
||||||
onClick = canIncrement and rowCallback("onInc", mediaId, function()
|
onClick = canIncrement and function()
|
||||||
sendCommand("increment", { mediaId = mediaId })
|
sendCommand("increment", { mediaId = mediaId })
|
||||||
end) or "onNoop",
|
end or "onNoop",
|
||||||
}))
|
}))
|
||||||
table.insert(rowChildren, ui.button({
|
table.insert(rowChildren, ui.button({
|
||||||
glyph = if isComplete then "check" else "circle-check",
|
glyph = if isComplete then "check" else "circle-check",
|
||||||
variant = if isComplete then "primary" else "ghost",
|
variant = if isComplete then "primary" else "ghost",
|
||||||
tooltip = tr("mark_complete"),
|
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 })
|
sendCommand("complete", { mediaId = mediaId })
|
||||||
end),
|
end,
|
||||||
}))
|
}))
|
||||||
table.insert(rowChildren, ui.button({
|
table.insert(rowChildren, ui.button({
|
||||||
glyph = "external-link",
|
glyph = "external-link",
|
||||||
variant = "ghost",
|
variant = "ghost",
|
||||||
tooltip = tr("open_anilist"),
|
tooltip = tr("open_anilist"),
|
||||||
onClick = rowCallback("onOpen", mediaId, function()
|
onClick = function()
|
||||||
sendCommand("open_media", { mediaId = mediaId, mediaType = entry.mediaType })
|
sendCommand("open_media", { mediaId = mediaId, mediaType = entry.mediaType })
|
||||||
end),
|
end,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
return ui.row({
|
return ui.row({
|
||||||
|
|||||||
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
id = "cleboost/anilist"
|
id = "cleboost/anilist"
|
||||||
name = "AniList (UNOFFICIAL)"
|
name = "AniList (UNOFFICIAL)"
|
||||||
version = "1.0.0"
|
version = "1.0.1"
|
||||||
plugin_api = 3
|
plugin_api = 9
|
||||||
author = "cleboost"
|
author = "cleboost"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
icon = "device-tv"
|
icon = "device-tv"
|
||||||
|
|||||||
Reference in New Issue
Block a user