full working application and initial commit

This commit is contained in:
2026-06-04 18:39:39 +02:00
commit 8524179793
86 changed files with 10107 additions and 0 deletions
+52
View File
@@ -0,0 +1,52 @@
import { mutation, query } from './_generated/server.js';
import { requireOwner } from './lib.js';
import {
dashboardRangeValidator,
editorModeValidator,
moodValidator,
themePreferenceValidator
} from './validators.js';
const defaults = {
theme: 'system' as const,
defaultMood: 'neutral' as const,
editorMode: 'split' as const,
dashboardRange: '30d' as const
};
export const get = query({
args: {},
handler: async (ctx) => {
const owner = await requireOwner(ctx);
const settings = await ctx.db
.query('settings')
.withIndex('by_owner', (q) => q.eq('owner', owner))
.unique();
return settings ?? defaults;
}
});
export const save = mutation({
args: {
theme: themePreferenceValidator,
defaultMood: moodValidator,
editorMode: editorModeValidator,
dashboardRange: dashboardRangeValidator
},
handler: async (ctx, args) => {
const owner = await requireOwner(ctx);
const existing = await ctx.db
.query('settings')
.withIndex('by_owner', (q) => q.eq('owner', owner))
.unique();
const next = { ...args, owner, updatedAt: Date.now() };
if (existing) {
await ctx.db.patch(existing._id, next);
return existing._id;
}
return await ctx.db.insert('settings', next);
}
});