8000 Integrated study plans in sidebar plugin explorer · danimihalca/vscode-leetcode@ebb9d04 · GitHub
[go: up one dir, main page]

Skip to content

Commit ebb9d04

Browse files
committed
Integrated study plans in sidebar plugin explorer
1 parent 5955141 commit ebb9d04

File tree

6 files changed

+86
-25
lines changed

6 files changed

+86
-25
lines changed

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
- English Document | [中文文档](https://github.com/LeetCode-OpenSource/vscode-leetcode/blob/master/docs/README_zh-CN.md)
2424

2525
## ❗️ Attention ❗️- Workaround to login to LeetCode endpoint
26+
2627
> Note: If you are using `leetcode.cn`, you can just ignore this section.
2728
2829
Recently we observed that [the extension cannot login to leetcode.com endpoint anymore](https://github.com/LeetCode-OpenSource/vscode-leetcode/issues/478). The root cause of this issue is that leetcode.com changed its login mechanism and so far there is no ideal way to fix that issue.
@@ -32,17 +33,21 @@ Thanks for [@yihong0618](https://github.com/yihong0618) provided a workaround wh
3233
> Note: If you want to use third-party login(**Recommended**), please make sure your account has been connected to the third-party. If you want to use `Cookie` login, click [here](https://github.com/LeetCode-OpenSource/vscode-leetcode/issues/478#issuecomment-564757098) to see the steps.
3334
3435
## Requirements
36+
3537
- [VS Code 1.30.1+](https://code.visualstudio.com/)
3638
- [Node.js 10+](https://nodejs.org)
37-
> NOTE: Please make sure that `Node` is in your `PATH` environment variable. You can also use the setting `leetcode.nodePath` to specify the location of your `Node.js` executable.
39+
> NOTE: Please make sure that `Node` is in your `PATH` environment variable. You can also use the setting `leetcode.nodePath` to specify the location of your `Node.js` executable.
3840
3941
## Quick Start
4042

4143
![demo](https://raw.githubusercontent.com/LeetCode-OpenSource/vscode-leetcode/master/docs/gifs/demo.gif)
4244

45+
![demo](./docs/imgs/demo_latest.png)
46+
4347
## Features
4448

4549
### Sign In/Out
50+
4651
<p align="center">
4752
<img src="https://raw.githubusercontent.com/LeetCode-OpenSource/vscode-leetcode/master/docs/imgs/sign_in.png" alt="Sign in" />
4853
</p>
@@ -52,16 +57,19 @@ Thanks for [@yihong0618](https://github.com/yihong0618) provided a workaround wh
5257
- You can also use the following command to sign in/out:
5358
- **LeetCode: Sign in**
5459
- **LeetCode: Sign out**
60+
5561
---
5662

5763
### Switch Endpoint
64+
5865
<p align="center">
5966
<img src="https://raw.githubusercontent.com/LeetCode-OpenSource/vscode-leetcode/master/docs/imgs/endpoint.png" alt="Switch Endpoint" />
6067
</p>
6168

6269
- By clicking the button ![btn_endpoint](https://raw.githubusercontent.com/LeetCode-OpenSource/vscode-leetcode/master/docs/imgs/btn_endpoint.png) at the **explorer's navigation bar**, you can switch between different endpoints.
6370

6471
- The supported endpoints are:
72+
6573
- **leetcode.com**
6674
- **leetcode.cn**
6775

@@ -70,6 +78,7 @@ Thanks for [@yihong0618](https://github.com/yihong0618) provided a workaround wh
7078
---
7179

7280
### Pick a Problem
81+
7382
<p align="center">
7483
<img src="https://raw.githubusercontent.com/LeetCode-OpenSource/vscode-leetcode/master/docs/imgs/pick_problem.png" alt="Pick a Problem" />
7584
</p>
@@ -86,11 +95,13 @@ Thanks for [@yihong0618](https://github.com/yihong0618) provided a workaround wh
8695
---
8796

8897
### Editor Shortcuts
98+
8999
<p align="center">
90100
<img src="https://raw.githubusercontent.com/LeetCode-OpenSource/vscode-leetcode/master/docs/imgs/shortcuts.png" alt="Editor Shortcuts" />
91101
</p>
92102

93103
- The extension supports 5 editor shortcuts (aka Code Lens):
104+
94105
- `Submit`: Submit your answer to LeetCode.
95106
- `Test`: Test your answer with customized test cases.
96107
- `Star/Unstar`: Star or unstar the current problem.
@@ -102,6 +113,7 @@ Thanks for [@yihong0618](https://github.com/yihong0618) provided a workaround wh
102113
---
103114

104115
### Search problems by Keywords
116+
105117
<p align="center">
106118
<img src="https://raw.githubusercontent.com/LeetCode-OpenSource/vscode-leetcode/master/docs/imgs/search.png" alt="Search problems by Keywords" />
107119
</p>
@@ -111,13 +123,13 @@ Thanks for [@yihong0618](https://github.com/yihong0618) provided a workaround wh
111123
---
112124

113125
### Manage Session
126+
114127
<p align="center">
115128
<img src="https://raw.githubusercontent.com/LeetCode-OpenSource/vscode-leetcode/master/docs/imgs/session.png" alt="Manage Session" />
116129
</p>
117130

118131
- To manage your LeetCode sessions, just clicking the `LeetCode: ***` at the bottom of the status bar. You can **switch** between sessions or **create**, **delete** a session.
119132

120-
121133
## Settings
122134

123135
| Setting Name | Description | Default Value |

docs/imgs/demo_latest.png

268 KB
Loading

src/explorer/LeetCodeNode.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the MIT license.
33

44
import { Command, Uri } from "vscode";
5-
import { IProblem, ProblemState } from "../shared";
5+
import { IProblem, ProblemState, StudyPlan } from "../shared";
66

77
export class LeetCodeNode {
88

@@ -47,12 +47,10 @@ export class LeetCodeNode {
4747
return this.isProblemNode;
4848
}
4949

50-
public get studyPlans(): Record<string, string>[] {
51-
return this.studyPlans;
50+
public get studyPlans(): StudyPlan[] {
51+
return this.data.studyPlans;
5252
}
5353

54-
//TODO: add study plan and subgroup
55-
5654
public get previewCommand(): Command {
5755
return {
5856
title: "Preview Problem",

src/explorer/LeetCodeTreeDataProvider.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCod
7979
return explorerNodeManager.getAllTagNodes();
8080
case Category.Company:
8181
return explorerNodeManager.getAllCompanyNodes();
82-
//TODO: handle get studyplans (and their subgroups)
82+
case Category.StudyPlans:
83+
return explorerNodeManager.getAllStudyPlansNodes();
8384
default:
8485
if (element.isProblem) {
8586
return [];

src/explorer/explorerNodeManager.ts

Lines changed: 58 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ import { Category, defaultProblem, ProblemState, SortingStrategy } from "../shar
99
import { shouldHideSolvedProblem } from "../utils/settingUtils";
1010
import { LeetCodeNode } from "./LeetCodeNode";
1111

12-
//TODO: predefine a list o study plans based on their slugs to be present in explorer
12+
const studyPlansToSearch: string[] = [
13+
'top-interview-150',
14+
'binary-search',
15+
'top-sql-50',
16+
'leetcode-75'
17+
];
1318
// currently no GraphQL API exists to fetch them all, temporary alternative
1419

1520
class ExplorerNodeManager implements Disposable {
@@ -33,19 +38,22 @@ class ExplorerNodeManager implements Disposable {
3338
this.tagSet.add(tag);
3439
}
3540
}
36-
let rrr = await list.listStudyPlanProblems("binary-search");
37-
const groupName = rrr.name;
38-
this.studyPlans[groupName] = new Set<string>();
39-
for (const subGroupKey in rrr.planSubGroups) {
40-
const subGroup = rrr.planSubGroups[subGroupKey];
41-
const subGroupName = subGroup.name;
42-
this.studyPlans[groupName].add(subGroupName);
43-
for (let questionKey in subGroup.questions) {
44-
this.explorerNodeMap[subGroup.questions[questionKey].id].studyPlans().append({groupName, subGroupName});
45-
}
4641

42+
for (const plan of studyPlansToSearch) {
43+
let studyPlanResult = await list.listStudyPlanProblems(plan);
44+
const groupName = studyPlanResult.name;
45+
this.studyPlans[groupName] = new Set<string>();
46+
console.log(this.explorerNodeMap.size);
47+
for (const subGroup of studyPlanResult.planSubGroups) {
48+
const subGroupName = subGroup.name;
49+
this.studyPlans[groupName].add(subGroupName);
50+
51+
for (let question of subGroup.questions) {
52+
const questionId: string = question.id;
53+
this.explorerNodeMap.get(questionId)?.studyPlans.push({group:groupName, subgroup:subGroupName});
54+
}
55+
}
4756
}
48-
console.log(rrr);
4957
}
5058

5159
public getRootNodes(): LeetCodeNode[] {
@@ -103,7 +111,17 @@ class ExplorerNodeManager implements Disposable {
103111
return res;
104112
}
105113

106-
//TODO: getter for all study plans (and for subgroups)
114+
public getAllStudyPlansNodes(): LeetCodeNode[] {
115+
const res: LeetCodeNode[] = [];
116+
for (const studyPlan in this.studyPlans) {
117+
res.push(new LeetCodeNode(Object.assign({}, defaultProblem, {
118+
id: `${Category.StudyPlans}.${studyPlan}`,
119+
name: studyPlan,
120+
}), false))
121+
}
122+
123+
return res;
124+
}
107125

108126
public getAllCompanyNodes(): LeetCodeNode[] {
109127
const res: LeetCodeNode[] = [];
@@ -147,6 +165,23 @@ class ExplorerNodeManager implements Disposable {
147165
// The sub-category node's id is named as {Category.SubName}
148166
const metaInfo: string[] = id.split(".");
149167
const res: LeetCodeNode[] = [];
168+
169+
switch (metaInfo[0]) {
170+
case Category.StudyPlans:
171+
if (metaInfo.length > 1) {
172+
for (const subgroup of this.studyPlans[metaInfo[1]].values()) {
173+
res.push(new LeetCodeNode(Object.assign({}, defaultProblem, {
174+
id: `${Category.StudyPlanSubgroup}.${metaInfo[1]}.${subgroup}`,
175+
name: subgroup,
176+
}), false))
177+
}
178+
}
179+
break;
180+
181+
default:
182+
break;
183+
}
184+
150185
for (const node of this.explorerNodeMap.values()) {
151186
switch (metaInfo[0]) {
152187
case Category.Company:
@@ -164,7 +199,16 @@ class ExplorerNodeManager implements Disposable {
164199
res.push(node);
165200
}
166201
break;
167-
//TODO: handle study plans
202+
203+
case Category.StudyPlanSubgroup:
204+
const group = metaInfo[1];
205+
const subgroup = metaInfo[2];
206+
207+
if (node.studyPlans.find(e => e.group === group && e.subgroup === subgroup)) {
208+
res.push(node);
209+
}
210+
break;
211+
168212
default:
169213
break;
170214
}

src/shared.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ export enum Endpoint {
7070
LeetCodeCN = "leetcode-cn",
7171
}
7272

73+
export interface StudyPlan {
74+
group: string,
75+
subgroup: string
76+
}
77+
7378
export interface IProblem {
7479
isFavorite: boolean;
7580
locked: boolean;
@@ -80,7 +85,7 @@ export interface IProblem {
8085
passRate: string;
8186
companies: string[];
8287
tags: string[];
83-
studyPlans: Record<string, string>[];
88+
studyPlans: StudyPlan[];
8489
}
8590

8691
export const defaultProblem: IProblem = {
@@ -93,7 +98,7 @@ export const defaultProblem: IProblem = {
9398
passRate: "",
9499
companies: [] as string[],
95100
tags: [] as string[],
96-
studyPlans: [] as Record<string, string>[]
101+
studyPlans: [] as StudyPlan[]
97102
};
98103

99104
export enum Category {
@@ -102,7 +107,8 @@ export enum Category {
102107
Tag = "Tag",
103108
Company = "Company",
104109
Favorite = "Favorite",
105-
StudyPlans = "Study Plans"
110+
StudyPlans = "Study Plans",
111+
StudyPlanSubgroup = "Study Plan Subgroup"
106112
}
107113

108114
export const supportedPlugins: string[] = [

0 commit comments

Comments
 (0)
0