Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lua/leetcode-plugins/cn/queries.lua
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,15 @@ queries.session_progress = [[
}
}
]]

queries.hot100 = [[
query studyPlanV2Detail($planSlug: String!) {
studyPlanV2Detail(planSlug: $planSlug) {
planSubGroups {
questions {
titleSlug
}
}
}
}
]]
7 changes: 7 additions & 0 deletions lua/leetcode-ui/group/page/problems.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,19 @@ local daily = Button("Daily", {
on_press = cmd.qot,
})

local hot100 = Button("Hot 100", {
icon = "󱐋",
sc = "h",
on_press = cmd.hot100,
})

local back = BackButton("menu")

page:insert(Buttons({
list,
random,
daily,
hot100,
back,
}))

Expand Down
23 changes: 23 additions & 0 deletions lua/leetcode/api/problems.lua
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,29 @@ function Problems.question_of_today(cb)
})
end

---@param cb function
function Problems.hot100(cb)
local query = queries.hot100
local variables = { planSlug = "top-100-liked" }

utils.query(query, variables, {
callback = function(res, err)
if err then
return cb(nil, err)
end

local groups = res.data.studyPlanV2Detail.planSubGroups
local questions = {}
for _, group in ipairs(groups) do
for _, q in ipairs(group.questions) do
table.insert(questions, q)
end
end
cb(questions)
end,
})
end

function Problems.translated_titles(cb)
local query = queries.translations

Expand Down
12 changes: 12 additions & 0 deletions lua/leetcode/api/queries.lua
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,16 @@ queries.session_progress = [[
}
]]

queries.hot100 = [[
query studyPlanV2Detail($planSlug: String!) {
studyPlanV2Detail(planSlug: $planSlug) {
planSubGroups {
questions {
titleSlug
}
}
}
}
]]

return queries
31 changes: 31 additions & 0 deletions lua/leetcode/command/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,36 @@ function cmd.random_question(opts)
Question(item):mount()
end

function cmd.hot100()
require("leetcode.utils").auth_guard()

local problems_api = require("leetcode.api.problems")
local problemlist = require("leetcode.cache.problemlist")
local picker = require("leetcode.picker")

problems_api.hot100(function(questions, err)
if err then
return log.err(err)
end

local slug_order = {}
for i, q in ipairs(questions) do
slug_order[q.titleSlug] = i
end

local cached = problemlist.get()
local questions = vim.tbl_filter(function(q)
return slug_order[q.title_slug] ~= nil
end, cached)

table.sort(questions, function(a, b)
return slug_order[a.title_slug] < slug_order[b.title_slug]
end)

picker.question(questions, {})
end)
end

function cmd.start_with_cmd()
local leetcode = require("leetcode")
if leetcode.start(false) then
Expand Down Expand Up @@ -630,6 +660,7 @@ cmd.commands = {
-- },
-- update = { cmd.update_sessions },
-- },
hot100 = { cmd.hot100 },
list = {
cmd.problems,
_args = arguments.list,
Expand Down