-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: 修复进度下拉选项颜色错误 * refactor: 增加站点设置组件,将同步题目进度组件迁移至设置组件内部 * optim: 优化useQuestProgress,实现全局共享数据 * refactor: ProblemCatetory.tsx拆分到多个文件 * feature: 新增自定义选项的功能 * refactor: 用useSyncExternalStore重写useStorage,实现同标签页组件共享相同state * fix: 修复Form.Control在Link内部导致颜色选择器无法正常显示的问题 * feature: 实时预览进度选项自定义效果
- Loading branch information
1 parent
a96bae9
commit 69c3e02
Showing
21 changed files
with
955 additions
and
490 deletions.
There are no files selected for viewing
157 changes: 157 additions & 0 deletions
157
components/ProblemCatetory/ProblemCategoryList/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
import { ShareIcon } from "@components/icons"; | ||
import RatingCircle, { ColorRating } from "@components/RatingCircle"; | ||
import { | ||
OptionEntry, | ||
ProgressKeyType, | ||
useProgressOptions, | ||
useQuestProgress, | ||
} from "@hooks/useProgress"; | ||
import { hashCode } from "@utils/hash"; | ||
import Form from "react-bootstrap/esm/Form"; | ||
|
||
const getCols = (l: number) => { | ||
if (l < 12) { | ||
return ""; | ||
} | ||
if (l < 20) { | ||
return "col2"; | ||
} | ||
return "col3"; | ||
}; | ||
|
||
const title2id = (title: string) => { | ||
// title: number. title | ||
return title.split(". ")[0]; | ||
}; | ||
|
||
interface ProblemCategory { | ||
title: string; | ||
summary?: string; | ||
src?: string; | ||
original_src?: string; | ||
sort?: Number; | ||
isLeaf?: boolean; | ||
solution?: string | null; | ||
score?: Number | null; | ||
child?: ProblemCategory[]; | ||
isPremium?: boolean; | ||
last_update?: string; | ||
} | ||
|
||
interface ProblemCategoryListProps { | ||
optionKeys: ProgressKeyType[]; | ||
getOption: (key?: ProgressKeyType) => OptionEntry; | ||
allProgress: Record<string, ProgressKeyType>; | ||
updateProgress: (questID: string, progress: ProgressKeyType) => void; | ||
removeProgress: (questID: string) => void; | ||
data: ProblemCategory; | ||
showEn?: boolean; | ||
showRating?: boolean; | ||
showPremium?: boolean; | ||
} | ||
|
||
function ProblemCategoryList({ | ||
optionKeys, | ||
getOption, | ||
allProgress, | ||
updateProgress, | ||
removeProgress, | ||
data, | ||
showEn, | ||
showRating, | ||
showPremium, | ||
}: ProblemCategoryListProps) { | ||
// Event handlers | ||
const handleProgressSelectChange = ( | ||
questID: string, | ||
progress: ProgressKeyType | ||
) => { | ||
if (progress === getOption().key) { | ||
removeProgress(questID); | ||
} else { | ||
updateProgress(questID, progress); | ||
} | ||
}; | ||
|
||
return ( | ||
<div className="shadow rounded p-2 leaf"> | ||
<h3 className="title" id={`${hashCode(data.title || "")}`}> | ||
{data.title} | ||
</h3> | ||
{data.summary && ( | ||
<p | ||
className="p-2 rounded summary bg-secondary-subtle text-warning-emphasis" | ||
dangerouslySetInnerHTML={{ __html: data.summary }} | ||
></p> | ||
)} | ||
<ul className={`list p-2 ${data.child && getCols(data.child.length)}`}> | ||
{data.child && | ||
data.child | ||
.filter((item) => !item.isPremium || showPremium) | ||
.map((item) => { | ||
const id = title2id(item.title); | ||
const progressKey = allProgress[id]; | ||
const option = getOption(progressKey); | ||
|
||
const rating = Number(item.score); | ||
|
||
return ( | ||
<li | ||
className="d-flex justify-content-between" | ||
key={hashCode(item.title || "")} | ||
> | ||
<div> | ||
<a | ||
href={"https://leetcode.cn/problems" + item.src} | ||
target="_blank" | ||
> | ||
{item.title + (item.isPremium ? " (会员题)" : "")} | ||
</a> | ||
{showEn && ( | ||
<a | ||
className="ms-2" | ||
href={"https://leetcode.com/problems" + item.src} | ||
target="_blank" | ||
> | ||
<ShareIcon height={16} width={16} /> | ||
</a> | ||
)} | ||
</div> | ||
{item.score && showRating ? ( | ||
<div className="ms-2 text-nowrap d-flex justify-content-center align-items-center pb-rating-bg"> | ||
<RatingCircle rating={rating} /> | ||
<ColorRating className="rating-text" rating={rating}> | ||
{rating.toFixed(0)} | ||
</ColorRating> | ||
</div> | ||
) : null} | ||
<div className="d-flex align-items-center ms-2"> | ||
<Form.Select | ||
style={{ | ||
color: option.color, | ||
}} | ||
value={option.key} | ||
onChange={(e) => | ||
handleProgressSelectChange(id, e.target.value) | ||
} | ||
> | ||
{optionKeys.map((p) => ( | ||
<option | ||
key={p} | ||
value={p} | ||
style={{ color: getOption(p).color }} | ||
> | ||
{getOption(p).label} | ||
</option> | ||
))} | ||
</Form.Select> | ||
</div> | ||
</li> | ||
); | ||
})} | ||
</ul> | ||
</div> | ||
); | ||
} | ||
|
||
export default ProblemCategoryList; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Nav } from "react-bootstrap"; | ||
import { SettingTabType } from "./config"; | ||
|
||
interface SidebarProps { | ||
tabs: SettingTabType[]; | ||
activeTab: string; | ||
onTabChange: (key: string) => void; | ||
} | ||
|
||
const Sidebar = ({ tabs, activeTab, onTabChange }: SidebarProps) => { | ||
return ( | ||
<Nav variant="pills" className="flex-column sticky-top"> | ||
{tabs.map((tab) => ( | ||
<Nav.Item key={tab.key}> | ||
<Nav.Link | ||
active={activeTab === tab.key} | ||
onClick={() => onTabChange(tab.key)} | ||
className="cursor-pointer sidebar-link text-start" | ||
> | ||
<span className="mx-2">{tab.icon}</span> | ||
{tab.title} | ||
</Nav.Link> | ||
</Nav.Item> | ||
))} | ||
</Nav> | ||
); | ||
}; | ||
|
||
export default Sidebar; |
Oops, something went wrong.