Files
Momento/memento-note/lib/label-storage.ts
Sepehr Ramezani e4d4e23dc7 chore: clean up repo for public release
- Remove BMAD framework, IDE configs, dev screenshots, test files,
  internal docs, and backup files
- Rename keep-notes/ to memento-note/
- Update all references from keep-notes to memento-note
- Add Apache 2.0 license with Commons Clause (non-commercial restriction)
- Add clean .gitignore and .env.docker.example
2026-04-20 22:48:06 +02:00

58 lines
1.6 KiB
TypeScript

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)
}
}