Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: add daily challenge problem pick (#919)#981

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
Icathian-Rain wants to merge2 commits intoLeetCode-OpenSource:master
base:master
Choose a base branch
Loading
fromIcathian-Rain:feat/dailyproblem
Open
Show file tree
Hide file tree
Changes fromall 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
13 changes: 12 additions & 1 deletionpackage.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,6 +32,7 @@
"onCommand:leetcode.manageSessions",
"onCommand:leetcode.refreshExplorer",
"onCommand:leetcode.pickOne",
"onCommand:leetcode.pickDaily",
"onCommand:leetcode.showProblem",
"onCommand:leetcode.previewProblem",
"onCommand:leetcode.searchProblem",
Expand DownExpand Up@@ -82,6 +83,11 @@
"title": "Pick One",
"category": "LeetCode"
},
{
"command": "leetcode.pickDaily",
"title": "Pick Daily Problem",
"category": "LeetCode"
},
{
"command": "leetcode.showProblem",
"title": "Show Problem",
Expand DownExpand Up@@ -193,9 +199,14 @@
"group": "overflow@2"
},
{
"command": "leetcode.problems.sort",
"command": "leetcode.pickDaily",
"when": "view == leetCodeExplorer",
"group": "overflow@3"
},
{
"command": "leetcode.problems.sort",
"when": "view == leetCodeExplorer",
"group": "overflow@4"
}
],
"view/item/context": [
Expand Down
11 changes: 11 additions & 0 deletionssrc/commands/show.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -30,6 +30,7 @@ import { leetCodeSolutionProvider } from "../webview/leetCodeSolutionProvider";
import * as list from "./list";
import { getLeetCodeEndpoint } from "./plugin";
import { globalState } from "../globalState";
import { queryDailyProblem } from "../request/query-daily-problem";

export async function previewProblem(input: IProblem | vscode.Uri, isSideMode: boolean = false): Promise<void> {
let node: IProblem;
Expand DownExpand Up@@ -70,6 +71,16 @@ export async function pickOne(): Promise<void> {
await showProblemInternal(randomProblem);
}

export async function pickDaily(): Promise<void> {
const dailyProblemID: string = await queryDailyProblem();
const node: IProblem | undefined = explorerNodeManager.getNodeById(dailyProblemID);
if (!node) {
vscode.window.showErrorMessage(`Failed to resolve the problem with id: ${dailyProblemID}.`);
return;
}
await showProblemInternal(node);
}

export async function showProblem(node?: LeetCodeNode): Promise<void> {
if (!node) {
return;
Expand Down
1 change: 1 addition & 0 deletionssrc/extension.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -71,6 +71,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
}),
vscode.commands.registerCommand("leetcode.showProblem", (node: LeetCodeNode) => show.showProblem(node)),
vscode.commands.registerCommand("leetcode.pickOne", () => show.pickOne()),
vscode.commands.registerCommand("leetcode.pickDaily", () => show.pickDaily()),
vscode.commands.registerCommand("leetcode.searchProblem", () => show.searchProblem()),
vscode.commands.registerCommand("leetcode.showSolution", (input: LeetCodeNode | vscode.Uri) => show.showSolution(input)),
vscode.commands.registerCommand("leetcode.refreshExplorer", () => leetCodeTreeDataProvider.refresh()),
Expand Down
14 changes: 14 additions & 0 deletionssrc/request/query-daily-problem.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
import { getUrl, getDailyQueryStr, getDailyProblemID } from "../shared";
import { LcAxios } from "../utils/httpUtils";


export const queryDailyProblem = async (): Promise<string> => {
return LcAxios(getUrl("graphql"), {
method: "POST",
data: {
query: getDailyQueryStr(),
variables: {},
operationName: "questionOfToday"
},
}).then((res) => getDailyProblemID(res));
};
45 changes: 45 additions & 0 deletionssrc/shared.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,7 @@
// Licensed under the MIT license.

import * as vscode from "vscode";
import { AxiosResponse } from "axios";

export interface IQuickItemEx<T> extends vscode.QuickPickItem {
value: T;
Expand DownExpand Up@@ -156,3 +157,47 @@ export const getUrl = (key: string) => {
return urls[key];
}
};

export const dailyQueryStr = `
query questionOfToday {
activeDailyCodingChallengeQuestion {
question {
frontendQuestionId: questionFrontendId
}
}
}
`;

export const dailyQueryStrCn = `
query questionOfToday {
todayRecord {
question {
frontendQuestionId: questionFrontendId
}
}
}
`;

export const getDailyQueryStr = () => {
const leetCodeConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("leetcode");
const point = leetCodeConfig.get<string>("endpoint", Endpoint.LeetCode);
switch (point) {
case Endpoint.LeetCodeCN:
return dailyQueryStrCn;
case Endpoint.LeetCode:
default:
return dailyQueryStr;
}
};

export const getDailyProblemID = (res : AxiosResponse<any, any>) => {
const leetCodeConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("leetcode");
const point = leetCodeConfig.get<string>("endpoint", Endpoint.LeetCode);
switch (point) {
case Endpoint.LeetCodeCN:
return res.data.data.todayRecord[0].question.frontendQuestionId;
case Endpoint.LeetCode:
default:
return res.data.data.activeDailyCodingChallengeQuestion.question.frontendQuestionId;
}
}

[8]ページ先頭

©2009-2025 Movatter.jp