add notifications
This commit is contained in:
parent
8dc1d080d8
commit
975dd39437
77
lua/mrpy.lua
77
lua/mrpy.lua
|
|
@ -1,4 +1,5 @@
|
|||
local curl = require("plenary.curl")
|
||||
local notify = require("snacks.notifier").notify
|
||||
local M = {}
|
||||
|
||||
---@param data table
|
||||
|
|
@ -155,6 +156,7 @@ M._on_tempbuf_write = function(args)
|
|||
M._update_task(data)
|
||||
|
||||
vim.api.nvim_set_option_value("modified", false, { buf = args.buf })
|
||||
local notif_id = notify("updated task #" .. data.id, "info", {title="MrPy", style='fancy'})
|
||||
end
|
||||
|
||||
---@class SelectionItem
|
||||
|
|
@ -168,6 +170,7 @@ end
|
|||
|
||||
---@param item SelectionItem
|
||||
M._on_select_task = function(picker, item)
|
||||
local notif_id = notify("opening task #" .. item.id, "info", {title="MrPy", style='fancy'})
|
||||
local new_name = "[ClickUp] " .. item.name
|
||||
local new_buf_no = vim.api.nvim_create_buf(true, false)
|
||||
|
||||
|
|
@ -248,48 +251,52 @@ end
|
|||
|
||||
---@param data vim.api.keyset.create_user_command.command_args
|
||||
M.select_task = function(data)
|
||||
local tasks = M.latest_tasks()
|
||||
local notif_id = notify("fetching tasks", "warn", {timeout = 10000, title="MrPy", style='fancy'})
|
||||
vim.schedule(function()
|
||||
local tasks = M.latest_tasks()
|
||||
|
||||
---@type SelectionItem[]
|
||||
local items = {}
|
||||
---@type SelectionItem[]
|
||||
local items = {}
|
||||
|
||||
for tix, t in ipairs(tasks) do
|
||||
if string.sub(t.name, -7, -1) ~= "Absence" then
|
||||
local preview_frontmatter = ""
|
||||
for tix, t in ipairs(tasks) do
|
||||
if string.sub(t.name, -7, -1) ~= "Absence" then
|
||||
local preview_frontmatter = ""
|
||||
|
||||
---@type SelectionItem
|
||||
local prepared = {
|
||||
idx = tix,
|
||||
id = t.id,
|
||||
text = t.name .. t.id .. t.markdown_description,
|
||||
name = t.name,
|
||||
tags = M.retrieve_subkeys(t.tags, { "name" }),
|
||||
status = t.status.status,
|
||||
parent = t.parent,
|
||||
list = t.list.name,
|
||||
description = t.markdown_description,
|
||||
preview = {
|
||||
ft = "markdown",
|
||||
},
|
||||
action = M._on_select_task
|
||||
}
|
||||
---@type SelectionItem
|
||||
local prepared = {
|
||||
idx = tix,
|
||||
id = t.id,
|
||||
text = t.name .. t.id .. t.markdown_description,
|
||||
name = t.name,
|
||||
tags = M.retrieve_subkeys(t.tags, { "name" }),
|
||||
status = t.status.status,
|
||||
parent = t.parent,
|
||||
list = t.list.name,
|
||||
description = t.markdown_description,
|
||||
preview = {
|
||||
ft = "markdown",
|
||||
},
|
||||
action = M._on_select_task
|
||||
}
|
||||
|
||||
for _, k in ipairs({ "id", "name", "status", "tags", "parent" }) do
|
||||
preview_frontmatter = preview_frontmatter .. "\n" .. k .. ": " .. vim.json.encode(prepared[k])
|
||||
for _, k in ipairs({ "id", "name", "status", "tags", "parent" }) do
|
||||
preview_frontmatter = preview_frontmatter .. "\n" .. k .. ": " .. vim.json.encode(prepared[k])
|
||||
end
|
||||
|
||||
prepared.preview.text = "---" .. preview_frontmatter .. "\n---\n" .. t.markdown_description
|
||||
table.insert(items, #items + 1, prepared)
|
||||
end
|
||||
|
||||
prepared.preview.text = "---" .. preview_frontmatter .. "\n---\n" .. t.markdown_description
|
||||
table.insert(items, #items + 1, prepared)
|
||||
end
|
||||
end
|
||||
|
||||
require("snacks.picker").pick({
|
||||
title = "Select Task",
|
||||
format = M._item_format,
|
||||
preview = "preview",
|
||||
confirm = M._on_select_task,
|
||||
items = items
|
||||
})
|
||||
require("snacks.notifier").hide(notif_id)
|
||||
require("snacks.picker").pick({
|
||||
title = "Select Task",
|
||||
format = M._item_format,
|
||||
preview = "preview",
|
||||
confirm = M._on_select_task,
|
||||
items = items
|
||||
})
|
||||
end)
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
|
|||
Loading…
Reference in New Issue