## Bug Fixes ### Note Card Actions - Fix broken size change functionality (missing state declaration) - Implement React 19 useOptimistic for instant UI feedback - Add startTransition for non-blocking updates - Ensure smooth animations without page refresh - All note actions now work: pin, archive, color, size, checklist ### Markdown LaTeX Rendering - Add remark-math and rehype-katex plugins - Support inline equations with dollar sign syntax - Support block equations with double dollar sign syntax - Import KaTeX CSS for proper styling - Equations now render correctly instead of showing raw LaTeX ## Technical Details - Replace undefined currentNote references with optimistic state - Add optimistic updates before server actions for instant feedback - Use router.refresh() in transitions for smart cache invalidation - Install remark-math, rehype-katex, and katex packages ## Testing - Build passes successfully with no TypeScript errors - Dev server hot-reloads changes correctly
60 lines
1.5 KiB
TypeScript
60 lines
1.5 KiB
TypeScript
'use server'
|
|
|
|
import { revalidatePath } from 'next/cache'
|
|
import prisma from '@/lib/prisma'
|
|
import { auth } from '@/auth'
|
|
import { sendEmail } from '@/lib/mail'
|
|
|
|
async function checkAdmin() {
|
|
const session = await auth()
|
|
if (!session?.user?.id || (session.user as any).role !== 'ADMIN') {
|
|
throw new Error('Unauthorized: Admin access required')
|
|
}
|
|
return session
|
|
}
|
|
|
|
export async function testSMTP() {
|
|
const session = await checkAdmin()
|
|
const email = session.user?.email
|
|
|
|
if (!email) throw new Error("No admin email found")
|
|
|
|
const result = await sendEmail({
|
|
to: email,
|
|
subject: "Memento SMTP Test",
|
|
html: "<p>This is a test email from your Memento instance. <strong>SMTP is working!</strong></p>"
|
|
})
|
|
|
|
return result
|
|
}
|
|
|
|
export async function getSystemConfig() {
|
|
await checkAdmin()
|
|
const configs = await prisma.systemConfig.findMany()
|
|
return configs.reduce((acc, conf) => {
|
|
acc[conf.key] = conf.value
|
|
return acc
|
|
}, {} as Record<string, string>)
|
|
}
|
|
|
|
export async function updateSystemConfig(data: Record<string, string>) {
|
|
await checkAdmin()
|
|
|
|
try {
|
|
const operations = Object.entries(data).map(([key, value]) =>
|
|
prisma.systemConfig.upsert({
|
|
where: { key },
|
|
update: { value },
|
|
create: { key, value }
|
|
})
|
|
)
|
|
|
|
await prisma.$transaction(operations)
|
|
revalidatePath('/admin/settings')
|
|
return { success: true }
|
|
} catch (error) {
|
|
console.error('Failed to update settings:', error)
|
|
return { error: 'Failed to update settings' }
|
|
}
|
|
}
|