Files
omni-tools/src/utils/bookmark.ts

41 lines
887 B
TypeScript
Raw Normal View History

2025-07-13 22:50:26 +12:00
import { DefinedTool } from '@tools/defineTool';
const bookmarkedToolsKey = 'bookmarkedTools';
2025-07-13 23:49:26 +12:00
export function getBookmarkedToolPaths(): string[] {
2025-07-14 00:11:17 +12:00
return (
localStorage
.getItem(bookmarkedToolsKey)
?.split(',')
?.filter((path) => path) ?? []
);
2025-07-13 22:50:26 +12:00
}
export function isBookmarked(tool: DefinedTool): boolean {
2025-07-13 23:49:26 +12:00
return getBookmarkedToolPaths().some((path) => path === tool.path);
2025-07-13 22:50:26 +12:00
}
export function toggleBookmarked(tool: DefinedTool) {
if (isBookmarked(tool)) {
unbookmark(tool);
} else {
bookmark(tool);
}
}
function bookmark(tool: DefinedTool) {
localStorage.setItem(
bookmarkedToolsKey,
2025-07-14 00:11:17 +12:00
[tool.path, ...getBookmarkedToolPaths()].join(',')
2025-07-13 22:50:26 +12:00
);
}
function unbookmark(tool: DefinedTool) {
2025-07-14 00:11:17 +12:00
localStorage.setItem(
bookmarkedToolsKey,
getBookmarkedToolPaths()
.filter((path) => path !== tool.path)
.join(',')
);
2025-07-13 22:50:26 +12:00
}