irongit

A Neovim plugin enabling you to solve LeetCode problems.

feat: check if question is for premium users only

kawreauthored
parent a0aa8facommit 1128e48a6fbaea46c06239edd8c0d391f68f4bdfBrowse files

6 files changed, +29 -6

+1-1lua/leetcode-menu/layout/problems.lua
@@ -44,7 +44,7 @@ return Layout:init({
4444 list_btn,
4545 random_btn,
4646 qot_btn,
47- lang_btn,
47+ -- lang_btn,
4848 back_btn,
4949 },
5050 }),
+6-1lua/leetcode/api/types.lua
@@ -249,7 +249,7 @@
249249 ---@field frontend_id integer
250250 ---@field title string
251251 ---@field title_slug string
252----@field id_paid_only boolean
252+---@field is_paid_only boolean
253253 ---@field difficulty string
254254 ---@field likes integer
255255 ---@field dislikes integer
@@ -261,9 +261,14 @@
261261 ---@field testcase_list string[]
262262 ---@field meta_data lc.metadata
263263 ---@field stats question_stats
264+---@field topic_tags lc.topic_tag[]
264265
265266 ---@alias lc.question_res lc.QuestionResponse
266267
268+---@class lc.topic_tag
269+---@field name string
270+---@field slug string
271+
267272 ---@class question_stats
268273 ---@field acRate string
269274 ---@field totalAccepted string
+2-0lua/leetcode/config/init.lua
@@ -27,7 +27,9 @@ function config.apply(cfg)
2727
2828 config.debug = config.user.debug or false ---@diagnostic disable-line
2929 config.domain = "https://leetcode." .. config.user.domain
30+
3031 config.lang = config.user.lang
32+ config.sql = config.user.sql
3133 end
3234
3335 return config
+1-0lua/leetcode/config/template.lua
@@ -24,6 +24,7 @@
2424 ---| "mysql"
2525 ---| "mssql"
2626 ---| "oraclesql"
27+---| "postgresql"
2728
2829 ---@alias lc.domain
2930 ---| "com"
+9-2lua/leetcode/pickers/question.lua
@@ -95,11 +95,18 @@ return {
9595 sorter = conf.generic_sorter(opts),
9696 attach_mappings = function(prompt_bufnr, map)
9797 actions.select_default:replace(function()
98- actions.close(prompt_bufnr)
9998 local selection = action_state.get_selected_entry()
10099
101100 if not selection then return end
102- Question:init(selection.value)
101+
102+ local q = selection.value
103+ if q.paid_only and not config.auth.is_premium then
104+ log.warn("Question is for premium users only")
105+ return
106+ end
107+
108+ actions.close(prompt_bufnr)
109+ Question:init(q)
103110 end)
104111 return true
105112 end,
+10-2lua/leetcode/ui/question.lua
@@ -12,6 +12,7 @@ local utils = require("leetcode.utils")
1212 ---@field bufnr integer
1313 ---@field console lc.Console
1414 ---@field lang string
15+---@field sql string
1516 local question = {}
1617 question.__index = question
1718
@@ -23,7 +24,6 @@ _Lc_curr_question = 0
2324 ---@private
2425 function question:create_file()
2526 local snippets = self.q.code_snippets
26-
2727 local snippet = {}
2828
2929 for _, snip in pairs(snippets ~= vim.NIL and snippets or {}) do
@@ -89,11 +89,18 @@ function question:init(problem)
8989 local tabp = utils.detect_duplicate_question(problem.title_slug, config.lang)
9090 if tabp then
9191 pcall(vim.cmd.tabnext, tabp)
92- return log.info("Question already opened")
92+ log.info("Question already opened")
93+ return
9394 end
9495
9596 local q = api_question.by_title_slug(problem.title_slug)
97+ if q.is_paid_only and not config.auth.is_premium then
98+ log.warn("Question is for premium users only")
99+ return
100+ end
101+
96102 local lang = config.lang
103+ local sql = config.sql
97104
98105 local ft = utils.filetype(lang)
99106 local fn = string.format("%s.%s.%s", q.frontend_id, q.title_slug, ft)
@@ -103,6 +110,7 @@ function question:init(problem)
103110 file = file,
104111 q = q,
105112 lang = lang,
113+ sql = sql,
106114 }, self)
107115
108116 return obj:mount()