feat: design system overhaul — sidebar, AI chats, settings, brainstorm, color cleanup
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 12s

- Sidebar: dynamic brand-accent colors, brainstorm section restyled
- AI chat general: popup panel with expand/collapse, hides when contextual AI open
- AI chat contextual: tabs reordered (Actions first), X close button, height fix
- Settings: all tabs restyled, 6 new color presets (sage, terracotta, iron, etc.)
- Global color cleanup: emerald/orange hardcoded → brand-accent dynamic
- Brainstorm page: orange → brand-accent throughout
- PageEntry animation component added to key pages
- Floating AI button: bg-brand-accent instead of hardcoded black
- i18n: all 15 locales updated with new AI/billing keys
- Billing: freemium quota tracking, BYOK, stripe subscription scaffolding
- Admin: integrated into new design
- AGENTS.md + CLAUDE.md project rules added
This commit is contained in:
Antigravity
2026-05-16 12:59:30 +00:00
parent 1fcea6ed7d
commit bd495be965
2284 changed files with 395285 additions and 2327 deletions

View File

@@ -4,124 +4,103 @@ import { prisma } from '@/lib/prisma'
export async function GET(req: NextRequest) {
try {
// Check authentication
const session = await auth()
if (!session?.user?.id) {
return NextResponse.json(
{ success: false, error: 'Unauthorized' },
{ status: 401 }
)
return NextResponse.json({ success: false, error: 'Unauthorized' }, { status: 401 })
}
// Fetch all notes with related data
const notes = await prisma.note.findMany({
where: {
userId: session.user.id,
trashedAt: null
},
include: {
labelRelations: {
select: {
id: true,
name: true
}
},
notebook: {
select: {
id: true,
name: true
}
}
},
orderBy: {
createdAt: 'desc'
}
})
const userId = session.user.id
// Fetch labels separately
const labels = await prisma.label.findMany({
where: {
userId: session.user.id
},
include: {
notes: {
select: {
id: true
}
}
}
})
const [allNotes, labels, notebooks] = await Promise.all([
prisma.note.findMany({
where: { userId },
orderBy: { createdAt: 'asc' },
}),
prisma.label.findMany({
where: { userId },
include: { notes: { select: { id: true } } },
}),
prisma.notebook.findMany({
where: { userId },
include: { notes: { select: { id: true } } },
}),
])
// Fetch notebooks
const notebooks = await prisma.notebook.findMany({
where: {
userId: session.user.id
},
include: {
notes: {
select: {
id: true
}
}
const noteLabelMap = new Map<string, string[]>()
for (const label of labels) {
for (const note of label.notes) {
const arr = noteLabelMap.get(note.id) || []
arr.push(label.id)
noteLabelMap.set(note.id, arr)
}
})
}
// Create export object
const exportData = {
version: '1.0.0',
version: '2.0.0',
exportDate: new Date().toISOString(),
user: {
id: session.user.id,
email: session.user.email,
name: session.user.name
id: userId,
email: session.user.email ?? '',
name: session.user.name ?? '',
},
data: {
labels: labels.map(label => ({
id: label.id,
name: label.name,
color: label.color,
noteCount: label.notes.length
notebooks: notebooks.map(nb => ({
id: nb.id,
name: nb.name,
icon: nb.icon,
color: nb.color,
order: nb.order,
parentId: nb.parentId,
trashedAt: nb.trashedAt?.toISOString() ?? null,
createdAt: nb.createdAt.toISOString(),
updatedAt: nb.updatedAt.toISOString(),
noteIds: nb.notes.map(n => n.id),
})),
notebooks: notebooks.map(notebook => ({
id: notebook.id,
name: notebook.name,
noteCount: notebook.notes.length
labels: labels.map(lb => ({
id: lb.id,
name: lb.name,
color: lb.color,
notebookId: lb.notebookId,
type: lb.type,
createdAt: lb.createdAt.toISOString(),
updatedAt: lb.updatedAt.toISOString(),
noteIds: lb.notes.map(n => n.id),
})),
notes: notes.map(note => ({
id: note.id,
title: note.title,
content: note.content,
color: note.color,
isPinned: note.isPinned,
isArchived: note.isArchived,
type: note.type,
checkItems: note.checkItems,
images: note.images,
links: note.links,
createdAt: note.createdAt,
updatedAt: note.updatedAt,
notebookId: note.notebookId,
labelRelations: note.labelRelations.map(label => ({
id: label.id,
name: label.name
}))
}))
}
notes: allNotes.map(n => ({
id: n.id,
title: n.title,
content: n.content,
color: n.color,
isPinned: n.isPinned,
isArchived: n.isArchived,
type: n.type,
order: n.order,
isMarkdown: n.isMarkdown,
size: n.size,
autoGenerated: n.autoGenerated,
historyEnabled: n.historyEnabled,
checkItems: n.checkItems,
images: n.images,
links: n.links,
trashedAt: n.trashedAt?.toISOString() ?? null,
notebookId: n.notebookId,
createdAt: n.createdAt.toISOString(),
updatedAt: n.updatedAt.toISOString(),
contentUpdatedAt: n.contentUpdatedAt?.toISOString() ?? null,
labelIds: noteLabelMap.get(n.id) || [],
})),
},
}
// Return as JSON file
const jsonString = JSON.stringify(exportData, null, 2)
return new NextResponse(jsonString, {
headers: {
'Content-Type': 'application/json',
'Content-Disposition': `attachment; filename="memento-export-${new Date().toISOString().split('T')[0]}.json"`
}
'Content-Disposition': `attachment; filename="memento-export-${new Date().toISOString().split('T')[0]}.json"`,
},
})
} catch (error) {
console.error('Export error:', error)
return NextResponse.json(
{ success: false, error: 'Failed to export notes' },
{ status: 500 }
)
return NextResponse.json({ success: false, error: 'Failed to export notes' }, { status: 500 })
}
}

View File

@@ -3,162 +3,231 @@ import { auth } from '@/auth'
import { prisma } from '@/lib/prisma'
import { revalidatePath } from 'next/cache'
function parseDate(v: unknown): Date | null {
if (!v) return null
const d = new Date(v as string)
return isNaN(d.getTime()) ? null : d
}
export async function POST(req: NextRequest) {
try {
// Check authentication
const session = await auth()
if (!session?.user?.id) {
return NextResponse.json(
{ success: false, error: 'Unauthorized' },
{ status: 401 }
)
return NextResponse.json({ success: false, error: 'Unauthorized' }, { status: 401 })
}
// Parse form data
const userId = session.user.id
const formData = await req.formData()
const file = formData.get('file') as File
if (!file) {
return NextResponse.json(
{ success: false, error: 'No file provided' },
{ status: 400 }
)
return NextResponse.json({ success: false, error: 'No file provided' }, { status: 400 })
}
// Parse JSON file
const text = await file.text()
let importData: any
try {
importData = JSON.parse(text)
} catch (error) {
return NextResponse.json(
{ success: false, error: 'Invalid JSON file' },
{ status: 400 }
)
} catch {
return NextResponse.json({ success: false, error: 'Invalid JSON file' }, { status: 400 })
}
// Validate import data structure
if (!importData.data || !importData.data.notes) {
return NextResponse.json(
{ success: false, error: 'Invalid import format' },
{ status: 400 }
)
return NextResponse.json({ success: false, error: 'Invalid import format' }, { status: 400 })
}
let importedNotes = 0
let importedLabels = 0
let importedNotebooks = 0
const stats = { notes: 0, labels: 0, notebooks: 0, skipped: 0 }
// Import labels first
if (importData.data.labels && Array.isArray(importData.data.labels)) {
for (const label of importData.data.labels) {
// Check if label already exists
const existing = await prisma.label.findFirst({
where: {
userId: session.user.id,
name: label.name
}
})
// 1. Notebooks — parents first, preserve original IDs
if (importData.data.notebooks?.length) {
const sorted = [...importData.data.notebooks].sort((a: any, b: any) => {
if (!a.parentId && b.parentId) return -1
if (a.parentId && !b.parentId) return 1
return 0
})
if (!existing) {
await prisma.label.create({
data: {
userId: session.user.id,
name: label.name,
color: label.color
}
for (const nb of sorted) {
try {
await prisma.notebook.upsert({
where: { id: nb.id },
update: {
name: nb.name,
icon: nb.icon ?? null,
color: nb.color ?? null,
order: nb.order ?? 0,
parentId: nb.parentId ?? null,
trashedAt: parseDate(nb.trashedAt),
updatedAt: new Date(),
},
create: {
id: nb.id,
name: nb.name,
icon: nb.icon ?? null,
color: nb.color ?? null,
order: nb.order ?? 0,
parentId: nb.parentId ?? null,
trashedAt: parseDate(nb.trashedAt),
userId,
createdAt: parseDate(nb.createdAt) ?? new Date(),
updatedAt: parseDate(nb.updatedAt) ?? new Date(),
},
})
importedLabels++
stats.notebooks++
} catch (e: any) {
if (e.code === 'P2002') {
// unique constraint — try with new ID
const parentId = nb.parentId ?? null
await prisma.notebook.create({
data: {
name: nb.name,
icon: nb.icon ?? null,
color: nb.color ?? null,
order: nb.order ?? 0,
parentId,
trashedAt: parseDate(nb.trashedAt),
userId,
createdAt: parseDate(nb.createdAt) ?? new Date(),
updatedAt: parseDate(nb.updatedAt) ?? new Date(),
},
})
stats.notebooks++
} else {
stats.skipped++
}
}
}
}
// Import notebooks
const notebookIdMap = new Map<string, string>()
if (importData.data.notebooks && Array.isArray(importData.data.notebooks)) {
for (const notebook of importData.data.notebooks) {
// Check if notebook already exists
const existing = await prisma.notebook.findFirst({
where: {
userId: session.user.id,
name: notebook.name
}
})
let newNotebookId
if (!existing) {
const created = await prisma.notebook.create({
data: {
userId: session.user.id,
name: notebook.name,
order: 0
}
// 2. Labels — preserve original IDs
if (importData.data.labels?.length) {
for (const lb of importData.data.labels) {
try {
await prisma.label.upsert({
where: { id: lb.id },
update: {
name: lb.name,
color: lb.color ?? null,
notebookId: lb.notebookId ?? null,
type: lb.type ?? 'user',
},
create: {
id: lb.id,
name: lb.name,
color: lb.color ?? null,
notebookId: lb.notebookId ?? null,
type: lb.type ?? 'user',
userId,
createdAt: parseDate(lb.createdAt) ?? new Date(),
updatedAt: parseDate(lb.updatedAt) ?? new Date(),
},
})
newNotebookId = created.id
notebookIdMap.set(notebook.id, newNotebookId)
importedNotebooks++
} else {
notebookIdMap.set(notebook.id, existing.id)
stats.labels++
} catch {
stats.skipped++
}
}
}
// Import notes
if (importData.data.notes && Array.isArray(importData.data.notes)) {
for (const note of importData.data.notes) {
// Map notebook ID
const mappedNotebookId = notebookIdMap.get(note.notebookId) || null
// 3. Notes — preserve original IDs
if (importData.data.notes?.length) {
for (const n of importData.data.notes) {
try {
const labelIds: string[] = n.labelIds || []
const validLabelIds = labelIds.length
? await prisma.label.findMany({
where: { id: { in: labelIds }, userId },
select: { id: true },
}).then(ls => ls.map(l => l.id))
: []
// Get label IDs
const labelNames = (note.labels || note.labelRelations || []).map((l: any) => l.name).filter(Boolean)
const labels = await prisma.label.findMany({
where: {
userId: session.user.id,
name: {
in: labelNames
}
await prisma.note.upsert({
where: { id: n.id },
update: {
title: n.title || 'Untitled',
content: n.content || '',
color: n.color || 'default',
isPinned: n.isPinned ?? false,
isArchived: n.isArchived ?? false,
type: n.type || 'richtext',
order: n.order ?? 0,
isMarkdown: n.isMarkdown ?? false,
size: n.size || 'small',
autoGenerated: n.autoGenerated ?? false,
historyEnabled: n.historyEnabled ?? true,
checkItems: n.checkItems ?? undefined,
images: n.images ?? undefined,
links: n.links ?? undefined,
trashedAt: parseDate(n.trashedAt),
notebookId: n.notebookId ?? null,
contentUpdatedAt: parseDate(n.contentUpdatedAt),
updatedAt: new Date(),
labelRelations: {
set: validLabelIds.map(id => ({ id })),
},
},
create: {
id: n.id,
title: n.title || 'Untitled',
content: n.content || '',
color: n.color || 'default',
isPinned: n.isPinned ?? false,
isArchived: n.isArchived ?? false,
type: n.type || 'richtext',
order: n.order ?? 0,
isMarkdown: n.isMarkdown ?? false,
size: n.size || 'small',
autoGenerated: n.autoGenerated ?? false,
historyEnabled: n.historyEnabled ?? true,
checkItems: n.checkItems ?? undefined,
images: n.images ?? undefined,
links: n.links ?? undefined,
trashedAt: parseDate(n.trashedAt),
notebookId: n.notebookId ?? null,
userId,
createdAt: parseDate(n.createdAt) ?? new Date(),
updatedAt: parseDate(n.updatedAt) ?? new Date(),
contentUpdatedAt: parseDate(n.contentUpdatedAt),
labelRelations: {
connect: validLabelIds.map(id => ({ id })),
},
},
})
stats.notes++
} catch (e: any) {
if (e.code === 'P2002') {
await prisma.note.create({
data: {
title: n.title || 'Untitled',
content: n.content || '',
color: n.color || 'default',
isPinned: n.isPinned ?? false,
isArchived: n.isArchived ?? false,
type: n.type || 'richtext',
order: n.order ?? 0,
isMarkdown: n.isMarkdown ?? false,
size: n.size || 'small',
notebookId: n.notebookId ?? null,
userId,
createdAt: parseDate(n.createdAt) ?? new Date(),
updatedAt: parseDate(n.updatedAt) ?? new Date(),
contentUpdatedAt: parseDate(n.contentUpdatedAt),
},
})
stats.notes++
} else {
stats.skipped++
}
})
// Create note
await prisma.note.create({
data: {
userId: session.user.id,
title: note.title || 'Untitled',
content: note.content || '',
color: note.color || 'default',
isPinned: note.isPinned || false,
isArchived: note.isArchived || false,
type: note.type || 'richtext',
checkItems: note.checkItems || null,
images: note.images || null,
links: note.links || null,
notebookId: mappedNotebookId,
labelRelations: {
connect: labels.map(label => ({ id: label.id }))
}
}
})
importedNotes++
}
}
}
// Revalidate paths
revalidatePath('/')
revalidatePath('/settings/data')
return NextResponse.json({
success: true,
count: importedNotes,
labels: importedLabels,
notebooks: importedNotebooks
})
return NextResponse.json({ success: true, ...stats })
} catch (error) {
console.error('Import error:', error)
return NextResponse.json(
{ success: false, error: 'Failed to import notes' },
{ status: 500 }
)
return NextResponse.json({ success: false, error: 'Failed to import notes' }, { status: 500 })
}
}