irongit

A Neovim plugin enabling you to solve LeetCode problems.

60 lines1.3 KBLua
1---@class lc.Stats
2local Stats = {}
3
4Stats.daily = {} ---@type { streak?: number, today_completed?: boolean }
5Stats.progress = {} ---@type table<string, lc.Stats.QuestionCount>
6
7function Stats.update_streak()
8 local stats_api = require("leetcode.api.statistics")
9 local log = require("leetcode.logger")
10
11 stats_api.streak(function(res, err)
12 if err then
13 return log.err(err)
14 end
15
16 Stats.daily.streak = res.streakCount
17 Stats.daily.today_completed = res.todayCompleted
18
19 _Lc_state.menu:draw()
20 end)
21end
22
23function Stats.update_sessions()
24 local stats_api = require("leetcode.api.statistics")
25 local log = require("leetcode.logger")
26
27 Stats.progress = {}
28
29 -- stats_api.sessions(function(_, err)
30 -- if err then
31 -- return log.err(err)
32 -- end
33 --
34 -- _Lc_state.menu:draw()
35 -- end)
36
37 stats_api.session_progress(function(res, err)
38 if err then
39 return log.err(err)
40 end
41
42 Stats.progress = {}
43
44 local progress = res
45 for _, p in ipairs(progress) do
46 Stats.progress[p.difficulty:lower()] = p
47 end
48
49 _Lc_state.menu:draw()
50 end)
51end
52
53function Stats.update()
54 Stats.update_streak()
55 Stats.update_sessions()
56
57 _Lc_state.menu:draw()
58end
59
60return Stats