fix: unify theme system - fix theme switching persistence

- Unified localStorage key to 'theme-preference' across all components
- Fixed header.tsx using wrong localStorage key ('theme' instead of 'theme-preference')
- Added localStorage hybrid persistence for instant theme changes
- Removed router.refresh() which was causing stale data revert
- Replaced Blue theme with Sepia
- Consolidated auth() calls to prevent race conditions
- Updated UserSettingsData types to include all themes
This commit is contained in:
2026-01-18 22:33:41 +01:00
parent ef60dafd73
commit ddb67ba9e5
306 changed files with 59580 additions and 6063 deletions

View File

@@ -6,7 +6,8 @@ import { Note, CheckItem } from '@/lib/types'
import { auth } from '@/auth'
import { getAIProvider } from '@/lib/ai/factory'
import { cosineSimilarity, validateEmbedding, calculateRRFK, detectQueryType, getSearchWeights } from '@/lib/utils'
import { getSystemConfig, getConfigNumber, SEARCH_DEFAULTS } from '@/lib/config'
import { getSystemConfig, getConfigNumber, getConfigBoolean, SEARCH_DEFAULTS } from '@/lib/config'
import { contextualAutoTagService } from '@/lib/ai/services/contextual-auto-tag.service'
// Helper function to parse JSON strings from database
function parseNote(dbNote: any): Note {
@@ -337,6 +338,41 @@ export async function createNote(data: {
console.error('Embedding generation failed:', e);
}
// AUTO-LABELING: If no labels provided and auto-labeling is enabled, suggest labels
let labelsToUse = data.labels || null;
if ((!labelsToUse || labelsToUse.length === 0) && data.notebookId) {
try {
const autoLabelingEnabled = await getConfigBoolean('AUTO_LABELING_ENABLED', true);
const autoLabelingConfidence = await getConfigNumber('AUTO_LABELING_CONFIDENCE_THRESHOLD', 70);
if (autoLabelingEnabled) {
console.log('[AUTO-LABELING] Generating suggestions for new note in notebook:', data.notebookId);
const suggestions = await contextualAutoTagService.suggestLabels(
data.content,
data.notebookId,
session.user.id
);
// Apply suggestions with confidence >= threshold
const appliedLabels = suggestions
.filter(s => s.confidence >= autoLabelingConfidence)
.map(s => s.label);
if (appliedLabels.length > 0) {
labelsToUse = appliedLabels;
console.log(`[AUTO-LABELING] Applied ${appliedLabels.length} labels:`, appliedLabels);
} else {
console.log('[AUTO-LABELING] No suggestions met confidence threshold');
}
} else {
console.log('[AUTO-LABELING] Disabled in config');
}
} catch (error) {
console.error('[AUTO-LABELING] Failed to suggest labels:', error);
// Continue without auto-labeling on error
}
}
const note = await prisma.note.create({
data: {
userId: session.user.id,
@@ -345,7 +381,7 @@ export async function createNote(data: {
color: data.color || 'default',
type: data.type || 'text',
checkItems: data.checkItems ? JSON.stringify(data.checkItems) : null,
labels: data.labels ? JSON.stringify(data.labels) : null,
labels: labelsToUse ? JSON.stringify(labelsToUse) : null,
images: data.images ? JSON.stringify(data.images) : null,
links: data.links ? JSON.stringify(data.links) : null,
isArchived: data.isArchived || false,
@@ -360,8 +396,8 @@ export async function createNote(data: {
})
// Sync labels to ensure Label records exist
if (data.labels && data.labels.length > 0) {
await syncLabels(session.user.id, data.labels)
if (labelsToUse && labelsToUse.length > 0) {
await syncLabels(session.user.id, labelsToUse)
}
// Revalidate main page (handles both inbox and notebook views via query params)