@@ -36,71 +36,15 @@ function P.filter(items, opts)
3636 end , items )
3737end
3838
39- --- @param items lc.cache.Question[]
40- --- @param group_by_category boolean
41- --- @return lc.cache.Question[]
42- function P .group_by_category (items , group_by_category )
43- if not group_by_category then
44- return items
45- end
46-
47- local categories = {}
48- for _ , question in ipairs (items ) do
49- local tags = question .tags or question .topic_tags or {}
50- if # tags == 0 then
51- table.insert (categories , { category = " Other" , questions = { question } })
52- else
53- for _ , tag in ipairs (tags ) do
54- local category_name = tag .name or tag
55- local found = false
56- for _ , cat in ipairs (categories ) do
57- if cat .category == category_name then
58- table.insert (cat .questions , question )
59- found = true
60- break
61- end
62- end
63- if not found then
64- table.insert (categories , { category = category_name , questions = { question } })
65- end
66- end
67- end
68- end
69-
70- table.sort (categories , function (a , b ) return a .category < b .category end )
71-
72- local result = {}
73- for _ , cat in ipairs (categories ) do
74- table.insert (result , {
75- frontend_id = " ---" ,
76- title = " ─── " .. cat .category :upper () .. " ───" ,
77- title_slug = " __category_" .. cat .category ,
78- difficulty = " " ,
79- status = " category_header" ,
80- ac_rate = 0 ,
81- paid_only = false ,
82- is_category_header = true ,
83- })
84-
85- for _ , question in ipairs (cat .questions ) do
86- table.insert (result , question )
87- end
88- end
89-
90- return result
91- end
92-
9339--- @param content lc.cache.Question[]
9440--- @param opts table<string , string[]>
95- --- @param group_by_category boolean | nil
41+ ---
9642--- @return { entry : any , value : lc.cache.Question } []
97- function P .items (content , opts , group_by_category )
43+ function P .items (content , opts )
9844 local filtered = P .filter (content , opts )
99- local grouped = P .group_by_category (filtered , group_by_category )
100-
10145 return vim .tbl_map (function (item )
10246 return { entry = P .entry (item ), value = item }
103- end , grouped )
47+ end , filtered )
10448end
10549
10650--- @param question lc.cache.Question
@@ -128,14 +72,6 @@ local function display_question(question)
12872end
12973
13074function P .entry (item )
131- if item .is_category_header then
132- return {
133- { " " , " leetcode_normal" },
134- { " " , " leetcode_normal" },
135- { item .title , " leetcode_list" },
136- }
137- end
138-
13975 return {
14076 display_user_status (item ),
14177 display_difficulty (item ),
@@ -154,10 +90,6 @@ function P.ordinal(item)
15490end
15591
15692function P .select (selection , close )
157- if selection .is_category_header then
158- return
159- end
160-
16193 if selection .paid_only and not config .auth .is_premium then
16294 return log .warn (" Question is for premium users only" )
16395 end
0 commit comments