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

39 lines
842 B
TypeScript
Raw Normal View History

2025-07-13 22:50:26 +12:00
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
}
2025-07-14 14:01:54 +12:00
export function isBookmarked(toolPath: string): boolean {
return getBookmarkedToolPaths().some((path) => path === toolPath);
2025-07-13 22:50:26 +12:00
}
2025-07-14 14:01:54 +12:00
export function toggleBookmarked(toolPath: string) {
if (isBookmarked(toolPath)) {
unbookmark(toolPath);
2025-07-13 22:50:26 +12:00
} else {
2025-07-14 14:01:54 +12:00
bookmark(toolPath);
2025-07-13 22:50:26 +12:00
}
}
2025-07-14 14:01:54 +12:00
function bookmark(toolPath: string) {
2025-07-13 22:50:26 +12:00
localStorage.setItem(
bookmarkedToolsKey,
2025-07-14 14:01:54 +12:00
[toolPath, ...getBookmarkedToolPaths()].join(',')
2025-07-13 22:50:26 +12:00
);
}
2025-07-14 14:01:54 +12:00
function unbookmark(toolPath: string) {
2025-07-14 00:11:17 +12:00
localStorage.setItem(
bookmarkedToolsKey,
getBookmarkedToolPaths()
2025-07-14 14:01:54 +12:00
.filter((path) => path !== toolPath)
2025-07-14 00:11:17 +12:00
.join(',')
);
2025-07-13 22:50:26 +12:00
}