| 
2 | 2 | // Licensed under the MIT license.  | 
3 | 3 | 
 
  | 
4 | 4 | import * as vscode from "vscode";  | 
 | 5 | +import { leetCodeTreeDataProvider } from "../explorer/LeetCodeTreeDataProvider";  | 
5 | 6 | import { leetCodeExecutor } from "../leetCodeExecutor";  | 
6 | 7 | import { IQuickItemEx } from "../shared";  | 
7 |  | -import { Endpoint } from "../shared";  | 
 | 8 | +import { Endpoint, SortingStrategy } from "../shared";  | 
8 | 9 | import { DialogType, promptForOpenOutputChannel, promptForSignIn } from "../utils/uiUtils";  | 
9 | 10 | import { deleteCache } from "./cache";  | 
10 | 11 | 
 
  | 
@@ -52,3 +53,36 @@ export function getLeetCodeEndpoint(): string {  | 
52 | 53 |     const leetCodeConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("leetcode");  | 
53 | 54 |     return leetCodeConfig.get<string>("endpoint", Endpoint.LeetCode);  | 
54 | 55 | }  | 
 | 56 | + | 
 | 57 | +const SORT_ORDER: SortingStrategy[] = [  | 
 | 58 | +    SortingStrategy.None,  | 
 | 59 | +    SortingStrategy.AcceptanceRateAsc,  | 
 | 60 | +    SortingStrategy.AcceptanceRateDesc,  | 
 | 61 | +];  | 
 | 62 | + | 
 | 63 | +export async function switchSortingStrategy(): Promise<void> {  | 
 | 64 | +    const currentStrategy: SortingStrategy = getSortingStrategy();  | 
 | 65 | +    const picks: Array<IQuickItemEx<string>> = [];  | 
 | 66 | +    picks.push(  | 
 | 67 | +        ...SORT_ORDER.map((s: SortingStrategy) => {  | 
 | 68 | +            return {  | 
 | 69 | +                label: `${currentStrategy === s ? "$(check)" : "    "} ${s}`,  | 
 | 70 | +                value: s,  | 
 | 71 | +            };  | 
 | 72 | +        }),  | 
 | 73 | +    );  | 
 | 74 | + | 
 | 75 | +    const choice: IQuickItemEx<string> | undefined = await vscode.window.showQuickPick(picks);  | 
 | 76 | +    if (!choice || choice.value === currentStrategy) {  | 
 | 77 | +        return;  | 
 | 78 | +    }  | 
 | 79 | + | 
 | 80 | +    const leetCodeConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("leetcode");  | 
 | 81 | +    await leetCodeConfig.update("problems.sortStrategy", choice.value, true);  | 
 | 82 | +    await leetCodeTreeDataProvider.refresh();  | 
 | 83 | +}  | 
 | 84 | + | 
 | 85 | +export function getSortingStrategy(): SortingStrategy {  | 
 | 86 | +    const leetCodeConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("leetcode");  | 
 | 87 | +    return leetCodeConfig.get<SortingStrategy>("problems.sortStrategy", SortingStrategy.None);  | 
 | 88 | +}  | 
0 commit comments