Skip to content
Open
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
8 changes: 8 additions & 0 deletions background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ const generateRandomLeetCodeProblem = async () => {
try {
const problemSet = (await storage.get("problemSets")) ?? "all"
const difficulty = (await storage.get("difficulty")) ?? "all"
const category = (await storage.get("category")) ?? "all"
let leetCodeProblems = []
if (problemSet === "all") {
await storage.set("loading", true)
Expand Down Expand Up @@ -117,11 +118,18 @@ const generateRandomLeetCodeProblem = async () => {
}
const res = await fetch(chrome.runtime.getURL(problemSetURLs[problemSet]))
leetCodeProblems = await res.json()

if (difficulty !== "all") {
leetCodeProblems = leetCodeProblems.filter((problem) => {
return problem.difficulty.toLowerCase() === difficulty.toLowerCase()
})
}
if (category !== "all") {
leetCodeProblems = leetCodeProblems.filter((problem) => {
console.log(problem.category.toLowerCase(), category.toLowerCase())
return problem.category.toLowerCase() === category.toLowerCase()
})
}

let randomIndex = Math.floor(Math.random() * leetCodeProblems.length)
// If the problem is premium, then skip it and go to the next problem until you find a non-premium problem
Expand Down
34 changes: 34 additions & 0 deletions components/SettingDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import SettingLabel from "./SettingLabel"
const SettingDrawer = ({ close, setClose }) => {
const [problemSets, setProblemSets] = useStorage<string>("problemSets")
const [difficulty, setDifficulty] = useStorage<string>("difficulty")
const [category, setCategory] = useStorage<string>("category")
const [leetcodeProblemSolved] = useStorage<boolean>("leetCodeProblemSolved")
const settingList = [
{
Expand Down Expand Up @@ -43,7 +44,40 @@ const SettingDrawer = ({ close, setClose }) => {
!leetcodeProblemSolved ? updateStorage() : null
}
}
},
{
name: "Problem Category",
description: "Choose the category you'd like to solve",
dropdownProps: {
options: {
all: "All categories",
"arrays & hashing": "Arrays & Hashing",
"two pointers": "Two Pointers",
"sliding window": "Sliding Window",
stack: "Stack",
"binary search": "Binary Search",
"linked list": "Linked List",
trees: "Trees",
tries: "Tries",
"heap / priority queue": "Heap / Priority Queue",
backtracking: "Backtracking",
graphs: "Graphs",
"advanced graphs": "Advanced Graphs",
"1-d dynamic programming": "1-D Dynamic Programming",
"2-d dynamic programming": "2-D Dynamic Programming",
greedy: "Greedy",
intervals: "Intervals",
"math & geometry": "Math & Geometry",
"bit manipulation": "Bit Manipulation",
javascript: "JavaScript"
},
defaultValue: category,
handleChange: async (e) => {
setCategory(e.target.value)
!leetcodeProblemSolved ? updateStorage() : null
}
}
}
/* TODO: Add this feature later
{
name: "Number of problems to solve",
Expand Down