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 curl = require("plenary.curl")
|
||||||
|
local notify = require("snacks.notifier").notify
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
---@param data table
|
---@param data table
|
||||||
|
|
@ -155,6 +156,7 @@ M._on_tempbuf_write = function(args)
|
||||||
M._update_task(data)
|
M._update_task(data)
|
||||||
|
|
||||||
vim.api.nvim_set_option_value("modified", false, { buf = args.buf })
|
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
|
end
|
||||||
|
|
||||||
---@class SelectionItem
|
---@class SelectionItem
|
||||||
|
|
@ -168,6 +170,7 @@ end
|
||||||
|
|
||||||
---@param item SelectionItem
|
---@param item SelectionItem
|
||||||
M._on_select_task = function(picker, item)
|
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_name = "[ClickUp] " .. item.name
|
||||||
local new_buf_no = vim.api.nvim_create_buf(true, false)
|
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
|
---@param data vim.api.keyset.create_user_command.command_args
|
||||||
M.select_task = function(data)
|
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[]
|
---@type SelectionItem[]
|
||||||
local items = {}
|
local items = {}
|
||||||
|
|
||||||
for tix, t in ipairs(tasks) do
|
for tix, t in ipairs(tasks) do
|
||||||
if string.sub(t.name, -7, -1) ~= "Absence" then
|
if string.sub(t.name, -7, -1) ~= "Absence" then
|
||||||
local preview_frontmatter = ""
|
local preview_frontmatter = ""
|
||||||
|
|
||||||
---@type SelectionItem
|
---@type SelectionItem
|
||||||
local prepared = {
|
local prepared = {
|
||||||
idx = tix,
|
idx = tix,
|
||||||
id = t.id,
|
id = t.id,
|
||||||
text = t.name .. t.id .. t.markdown_description,
|
text = t.name .. t.id .. t.markdown_description,
|
||||||
name = t.name,
|
name = t.name,
|
||||||
tags = M.retrieve_subkeys(t.tags, { "name" }),
|
tags = M.retrieve_subkeys(t.tags, { "name" }),
|
||||||
status = t.status.status,
|
status = t.status.status,
|
||||||
parent = t.parent,
|
parent = t.parent,
|
||||||
list = t.list.name,
|
list = t.list.name,
|
||||||
description = t.markdown_description,
|
description = t.markdown_description,
|
||||||
preview = {
|
preview = {
|
||||||
ft = "markdown",
|
ft = "markdown",
|
||||||
},
|
},
|
||||||
action = M._on_select_task
|
action = M._on_select_task
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, k in ipairs({ "id", "name", "status", "tags", "parent" }) do
|
for _, k in ipairs({ "id", "name", "status", "tags", "parent" }) do
|
||||||
preview_frontmatter = preview_frontmatter .. "\n" .. k .. ": " .. vim.json.encode(prepared[k])
|
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
|
end
|
||||||
|
|
||||||
prepared.preview.text = "---" .. preview_frontmatter .. "\n---\n" .. t.markdown_description
|
|
||||||
table.insert(items, #items + 1, prepared)
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
require("snacks.picker").pick({
|
require("snacks.notifier").hide(notif_id)
|
||||||
title = "Select Task",
|
require("snacks.picker").pick({
|
||||||
format = M._item_format,
|
title = "Select Task",
|
||||||
preview = "preview",
|
format = M._item_format,
|
||||||
confirm = M._on_select_task,
|
preview = "preview",
|
||||||
items = items
|
confirm = M._on_select_task,
|
||||||
})
|
items = items
|
||||||
|
})
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue