Skip to content

随机一题可以指定 tag 分类 #220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 23, 2023
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## version 2.19.7

- 随机一题可以指定 tag 分类

## version 2.19.6

- 获取题目错误,则不生成文件
Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-leetcode-problem-rating",
"displayName": "LeetCode",
"description": "%main.description%",
"version": "2.19.6",
"version": "2.19.7",
"author": "ccagml",
"publisher": "ccagml",
"license": "MIT",
Expand Down Expand Up @@ -76,7 +76,8 @@
{
"command": "lcpr.pickOne",
"title": "%main.contributes.commands.lcpr.pickOne.title%",
"category": "LeetCode"
"category": "LeetCode",
"icon": "$(compass)"
},
{
"command": "lcpr.deleteAllCache",
Expand Down Expand Up @@ -372,17 +373,17 @@
{
"command": "lcpr.pickOne",
"when": "view == QuestionExplorer",
"group": "overflow@0"
"group": "navigation@4"
},
{
"command": "lcpr.problems.sort",
"when": "view == QuestionExplorer",
"group": "overflow@1"
"group": "overflow@0"
},
{
"command": "lcpr.deleteAllCache",
"when": "view == QuestionExplorer",
"group": "overflow@2"
"group": "overflow@1"
},
{
"command": "lcpr.newBrickGroup",
Expand Down
53 changes: 52 additions & 1 deletion src/controller/TreeViewController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import { fileButtonService } from "../service/FileButtonService";
import * as fse from "fs-extra";
import { submissionService } from "../service/SubmissionService";
import { bricksDataService } from "../service/BricksDataService";
import { groupDao } from "../dao/groupDao";

// 视图控制器
class TreeViewController implements Disposable {
Expand Down Expand Up @@ -665,6 +666,45 @@ class TreeViewController implements Disposable {
}

public async pickOne(): Promise<void> {
const picks: Array<IQuickItemEx<string>> = [];

let last_pick = await groupDao.getPickOneTags();

let last_tag_set: Set<string> = new Set<string>();
last_pick.forEach((tag_name) => {
last_tag_set.add(tag_name);
});

for (const tag of this.tagSet.values()) {
let pick_item: IQuickItemEx<string> = {
label: tag,
detail: "",
value: tag,
};
if (last_tag_set.has(tag)) {
pick_item.picked = true;
}

picks.push(pick_item);
}

const choice: Array<IQuickItemEx<string>> | undefined = await window.showQuickPick(picks, {
title: "指定Tag类型",
matchOnDescription: false,
matchOnDetail: false,
placeHolder: "指定Tag类型",
canPickMany: true,
});
if (!choice) {
return;
}

// 写入选择
let cur_tag_set: Set<string> = new Set<string>();
choice.forEach((element) => {
cur_tag_set.add(element.value);
});

const problems: IProblem[] = await this.getAllProblems();
let randomProblem: IProblem;

Expand All @@ -678,7 +718,11 @@ class TreeViewController implements Disposable {
problems.forEach((element) => {
if (element.scoreData?.Rating) {
if (element.scoreData.Rating >= need_min && element.scoreData.Rating <= need_max) {
temp_problems.push(element);
for (const q_tag of element.tags) {
if (cur_tag_set.has(q_tag)) {
temp_problems.push(element);
}
}
}
}
});
Expand All @@ -689,6 +733,13 @@ class TreeViewController implements Disposable {
if (randomProblem) {
await this.showProblemInternal(randomProblem);
}

// 写入
let new_pick_one_tags: Array<string> = [];
for (const new_tag of cur_tag_set) {
new_pick_one_tags.push(new_tag);
}
await groupDao.setPickOneTags(new_pick_one_tags);
}

public async showProblemInternal(node: IProblem): Promise<void> {
Expand Down
11 changes: 11 additions & 0 deletions src/dao/groupDao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,17 @@ class GroupDao {
old_data.all_group = all_group;
this._write_data(old_data);
}

public async getPickOneTags() {
let old_data = await this._read_data();
let pick_one_tags = old_data.pick_one_tags || [];
return pick_one_tags;
}
public async setPickOneTags(new_pick_one_tags) {
let old_data = await this._read_data();
old_data.pick_one_tags = new_pick_one_tags;
this._write_data(old_data);
}
}

export const groupDao: GroupDao = new GroupDao();