Implement bookmarking

This commit is contained in:
Yihao Wang
2025-07-13 23:49:26 +12:00
parent 0e09e9e027
commit 0d3a17a923
2 changed files with 45 additions and 5 deletions

View File

@@ -2,12 +2,12 @@ import { DefinedTool } from '@tools/defineTool';
const bookmarkedToolsKey = 'bookmarkedTools';
export function getBookmarkedTools(): string[] {
export function getBookmarkedToolPaths(): string[] {
return localStorage.getItem(bookmarkedToolsKey)?.split(',') ?? [];
}
export function isBookmarked(tool: DefinedTool): boolean {
return getBookmarkedTools().some((path) => path === tool.path);
return getBookmarkedToolPaths().some((path) => path === tool.path);
}
export function toggleBookmarked(tool: DefinedTool) {
@@ -21,7 +21,7 @@ export function toggleBookmarked(tool: DefinedTool) {
function bookmark(tool: DefinedTool) {
localStorage.setItem(
bookmarkedToolsKey,
tool.path + localStorage.getItem(bookmarkedToolsKey)
tool.path + ',' + (localStorage.getItem(bookmarkedToolsKey) ?? '')
);
}