Fix tests and add changelog
This commit is contained in:
57
keep-notes/lib/label-storage.ts
Normal file
57
keep-notes/lib/label-storage.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import { LabelColorName } from './types'
|
||||
|
||||
const STORAGE_KEY = 'memento-label-colors'
|
||||
|
||||
// Store label colors in localStorage
|
||||
export function getLabelColor(label: string): LabelColorName {
|
||||
if (typeof window === 'undefined') return 'gray'
|
||||
|
||||
try {
|
||||
const stored = localStorage.getItem(STORAGE_KEY)
|
||||
if (!stored) return 'gray'
|
||||
|
||||
const colors = JSON.parse(stored) as Record<string, LabelColorName>
|
||||
return colors[label] || 'gray'
|
||||
} catch {
|
||||
return 'gray'
|
||||
}
|
||||
}
|
||||
|
||||
export function setLabelColor(label: string, color: LabelColorName) {
|
||||
if (typeof window === 'undefined') return
|
||||
|
||||
try {
|
||||
const stored = localStorage.getItem(STORAGE_KEY)
|
||||
const colors = stored ? JSON.parse(stored) as Record<string, LabelColorName> : {}
|
||||
colors[label] = color
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(colors))
|
||||
} catch (error) {
|
||||
console.error('Failed to save label color:', error)
|
||||
}
|
||||
}
|
||||
|
||||
export function getAllLabelColors(): Record<string, LabelColorName> {
|
||||
if (typeof window === 'undefined') return {}
|
||||
|
||||
try {
|
||||
const stored = localStorage.getItem(STORAGE_KEY)
|
||||
return stored ? JSON.parse(stored) : {}
|
||||
} catch {
|
||||
return {}
|
||||
}
|
||||
}
|
||||
|
||||
export function deleteLabelColor(label: string) {
|
||||
if (typeof window === 'undefined') return
|
||||
|
||||
try {
|
||||
const stored = localStorage.getItem(STORAGE_KEY)
|
||||
if (!stored) return
|
||||
|
||||
const colors = JSON.parse(stored) as Record<string, LabelColorName>
|
||||
delete colors[label]
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(colors))
|
||||
} catch (error) {
|
||||
console.error('Failed to delete label color:', error)
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,25 @@ export interface Note {
|
||||
updatedAt: Date;
|
||||
}
|
||||
|
||||
export interface LabelWithColor {
|
||||
name: string;
|
||||
color: LabelColorName;
|
||||
}
|
||||
|
||||
export const LABEL_COLORS = {
|
||||
gray: { bg: 'bg-gray-100 dark:bg-gray-800', text: 'text-gray-700 dark:text-gray-300', border: 'border-gray-300 dark:border-gray-600' },
|
||||
red: { bg: 'bg-red-100 dark:bg-red-900/30', text: 'text-red-700 dark:text-red-300', border: 'border-red-300 dark:border-red-600' },
|
||||
orange: { bg: 'bg-orange-100 dark:bg-orange-900/30', text: 'text-orange-700 dark:text-orange-300', border: 'border-orange-300 dark:border-orange-600' },
|
||||
yellow: { bg: 'bg-yellow-100 dark:bg-yellow-900/30', text: 'text-yellow-700 dark:text-yellow-300', border: 'border-yellow-300 dark:border-yellow-600' },
|
||||
green: { bg: 'bg-green-100 dark:bg-green-900/30', text: 'text-green-700 dark:text-green-300', border: 'border-green-300 dark:border-green-600' },
|
||||
teal: { bg: 'bg-teal-100 dark:bg-teal-900/30', text: 'text-teal-700 dark:text-teal-300', border: 'border-teal-300 dark:border-teal-600' },
|
||||
blue: { bg: 'bg-blue-100 dark:bg-blue-900/30', text: 'text-blue-700 dark:text-blue-300', border: 'border-blue-300 dark:border-blue-600' },
|
||||
purple: { bg: 'bg-purple-100 dark:bg-purple-900/30', text: 'text-purple-700 dark:text-purple-300', border: 'border-purple-300 dark:border-purple-600' },
|
||||
pink: { bg: 'bg-pink-100 dark:bg-pink-900/30', text: 'text-pink-700 dark:text-pink-300', border: 'border-pink-300 dark:border-pink-600' },
|
||||
}
|
||||
|
||||
export type LabelColorName = keyof typeof LABEL_COLORS
|
||||
|
||||
export const NOTE_COLORS = {
|
||||
default: {
|
||||
bg: 'bg-white dark:bg-zinc-900',
|
||||
|
||||
Reference in New Issue
Block a user