A Neovim plugin enabling you to solve LeetCode problems.
| 1 | local Popup = require("leetcode-ui.popup") |
| 2 | local Group = require("leetcode-ui.group") |
| 3 | local Lines = require("leetcode-ui.lines") |
| 4 | |
| 5 | local stats_api = require("leetcode.api.statistics") |
| 6 | local config = require("leetcode.config") |
| 7 | local Spinner = require("leetcode.logger.spinner") |
| 8 | local utils = require("leetcode-ui.utils") |
| 9 | |
| 10 | local log = require("leetcode.logger") |
| 11 | |
| 12 | ---@class lc.ui.SkillsPopup : lc.ui.Popup |
| 13 | ---@field renderer lc-ui.Renderer |
| 14 | local Skills = Popup:extend("LeetSkills") |
| 15 | |
| 16 | |
| 17 | local lines = Lines() |
| 18 | |
| 19 | table.sort(skills, function(a, b) |
| 20 | return a.problems_solved > b.problems_solved |
| 21 | end) |
| 22 | lines:append(config.icons.square, utils.diff_to_hl(name)) |
| 23 | lines:append(" " .. name) |
| 24 | |
| 25 | for _, skill in ipairs(skills) do |
| 26 | lines:endl() |
| 27 | lines:append(skill.tag, "leetcode_code") |
| 28 | lines:append((" x%d"):format(skill.problems_solved), "leetcode_alt") |
| 29 | end |
| 30 | |
| 31 | return lines |
| 32 | end |
| 33 | |
| 34 | ---@private |
| 35 | ---@param res lc.Skills.Res |
| 36 | |
| 37 | local group = Group({}, { spacing = 1 }) |
| 38 | |
| 39 | local order = { "advanced", "intermediate", "fundamental" } |
| 40 | for _, key in ipairs(order) do |
| 41 | group:insert(self:handle(key, res[key])) |
| 42 | end |
| 43 | |
| 44 | self.renderer:insert(group) |
| 45 | end |
| 46 | |
| 47 | |
| 48 | Skills.super.mount(self) |
| 49 | |
| 50 | local spinner = Spinner:start("fetching user skills", "dot") |
| 51 | stats_api.skills(function(res, err) |
| 52 | if err then |
| 53 | spinner:error(err.msg) |
| 54 | else |
| 55 | self:populate(res) |
| 56 | spinner:success("skills fetched") |
| 57 | Skills.super.draw(self) |
| 58 | end |
| 59 | end) |
| 60 | end |
| 61 | |
| 62 | |
| 63 | Skills.super.init(self, { |
| 64 | position = "50%", |
| 65 | size = { |
| 66 | width = 75, |
| 67 | height = "50%", |
| 68 | }, |
| 69 | enter = true, |
| 70 | focusable = true, |
| 71 | zindex = 50, |
| 72 | relative = "editor", |
| 73 | border = { |
| 74 | padding = { |
| 75 | top = 2, |
| 76 | bottom = 2, |
| 77 | left = 3, |
| 78 | right = 3, |
| 79 | }, |
| 80 | style = "rounded", |
| 81 | text = { |
| 82 | top = " Skills ", |
| 83 | }, |
| 84 | }, |
| 85 | buf_options = { |
| 86 | modifiable = false, |
| 87 | readonly = false, |
| 88 | }, |
| 89 | }) |
| 90 | end |
| 91 | |
| 92 | return Skills() |