Skip to content

Commit 4aa4b14

Browse files
authored
Merge pull request #220 from ccagml/main
随机一题可以指定 tag 分类
2 parents 4ab37cf + 916c607 commit 4aa4b14

File tree

4 files changed

+73
-6
lines changed

4 files changed

+73
-6
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## version 2.19.7
2+
3+
- 随机一题可以指定 tag 分类
4+
15
## version 2.19.6
26

37
- 获取题目错误,则不生成文件

package.json

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vscode-leetcode-problem-rating",
33
"displayName": "LeetCode",
44
"description": "%main.description%",
5-
"version": "2.19.6",
5+
"version": "2.19.7",
66
"author": "ccagml",
77
"publisher": "ccagml",
88
"license": "MIT",
@@ -76,7 +76,8 @@
7676
{
7777
"command": "lcpr.pickOne",
7878
"title": "%main.contributes.commands.lcpr.pickOne.title%",
79-
"category": "LeetCode"
79+
"category": "LeetCode",
80+
"icon": "$(compass)"
8081
},
8182
{
8283
"command": "lcpr.deleteAllCache",
@@ -372,17 +373,17 @@
372373
{
373374
"command": "lcpr.pickOne",
374375
"when": "view == QuestionExplorer",
375-
"group": "overflow@0"
376+
"group": "navigation@4"
376377
},
377378
{
378379
"command": "lcpr.problems.sort",
379380
"when": "view == QuestionExplorer",
380-
"group": "overflow@1"
381+
"group": "overflow@0"
381382
},
382383
{
383384
"command": "lcpr.deleteAllCache",
384385
"when": "view == QuestionExplorer",
385-
"group": "overflow@2"
386+
"group": "overflow@1"
386387
},
387388
{
388389
"command": "lcpr.newBrickGroup",

src/controller/TreeViewController.ts

+52-1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ import { fileButtonService } from "../service/FileButtonService";
7474
import * as fse from "fs-extra";
7575
import { submissionService } from "../service/SubmissionService";
7676
import { bricksDataService } from "../service/BricksDataService";
77+
import { groupDao } from "../dao/groupDao";
7778

7879
// 视图控制器
7980
class TreeViewController implements Disposable {
@@ -665,6 +666,45 @@ class TreeViewController implements Disposable {
665666
}
666667

667668
public async pickOne(): Promise<void> {
669+
const picks: Array<IQuickItemEx<string>> = [];
670+
671+
let last_pick = await groupDao.getPickOneTags();
672+
673+
let last_tag_set: Set<string> = new Set<string>();
674+
last_pick.forEach((tag_name) => {
675+
last_tag_set.add(tag_name);
676+
});
677+
678+
for (const tag of this.tagSet.values()) {
679+
let pick_item: IQuickItemEx<string> = {
680+
label: tag,
681+
detail: "",
682+
value: tag,
683+
};
684+
if (last_tag_set.has(tag)) {
685+
pick_item.picked = true;
686+
}
687+
688+
picks.push(pick_item);
689+
}
690+
691+
const choice: Array<IQuickItemEx<string>> | undefined = await window.showQuickPick(picks, {
692+
title: "指定Tag类型",
693+
matchOnDescription: false,
694+
matchOnDetail: false,
695+
placeHolder: "指定Tag类型",
696+
canPickMany: true,
697+
});
698+
if (!choice) {
699+
return;
700+
}
701+
702+
// 写入选择
703+
let cur_tag_set: Set<string> = new Set<string>();
704+
choice.forEach((element) => {
705+
cur_tag_set.add(element.value);
706+
});
707+
668708
const problems: IProblem[] = await this.getAllProblems();
669709
let randomProblem: IProblem;
670710

@@ -678,7 +718,11 @@ class TreeViewController implements Disposable {
678718
problems.forEach((element) => {
679719
if (element.scoreData?.Rating) {
680720
if (element.scoreData.Rating >= need_min && element.scoreData.Rating <= need_max) {
681-
temp_problems.push(element);
721+
for (const q_tag of element.tags) {
722+
if (cur_tag_set.has(q_tag)) {
723+
temp_problems.push(element);
724+
}
725+
}
682726
}
683727
}
684728
});
@@ -689,6 +733,13 @@ class TreeViewController implements Disposable {
689733
if (randomProblem) {
690734
await this.showProblemInternal(randomProblem);
691735
}
736+
737+
// 写入
738+
let new_pick_one_tags: Array<string> = [];
739+
for (const new_tag of cur_tag_set) {
740+
new_pick_one_tags.push(new_tag);
741+
}
742+
await groupDao.setPickOneTags(new_pick_one_tags);
692743
}
693744

694745
public async showProblemInternal(node: IProblem): Promise<void> {

src/dao/groupDao.ts

+11
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,17 @@ class GroupDao {
135135
old_data.all_group = all_group;
136136
this._write_data(old_data);
137137
}
138+
139+
public async getPickOneTags() {
140+
let old_data = await this._read_data();
141+
let pick_one_tags = old_data.pick_one_tags || [];
142+
return pick_one_tags;
143+
}
144+
public async setPickOneTags(new_pick_one_tags) {
145+
let old_data = await this._read_data();
146+
old_data.pick_one_tags = new_pick_one_tags;
147+
this._write_data(old_data);
148+
}
138149
}
139150

140151
export const groupDao: GroupDao = new GroupDao();

0 commit comments

Comments
 (0)