feat: improve AI Chat UX, add notebook summary, and fix shared/reminders routing
Some checks failed
Deploy to Production / Build and Deploy (push) Failing after 1m50s
Some checks failed
Deploy to Production / Build and Deploy (push) Failing after 1m50s
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
/**
|
||||
* Detect user's preferred language.
|
||||
* Priority:
|
||||
* 0. user-language cookie (explicit user choice, synced with localStorage)
|
||||
* 1. Most common language among user's notes (DB GROUP BY)
|
||||
* 2. Browser language hint (passed from server component via Accept-Language)
|
||||
* 3. Default: 'en'
|
||||
@@ -8,7 +9,7 @@
|
||||
|
||||
import { auth } from '@/auth'
|
||||
import { prisma } from '@/lib/prisma'
|
||||
import { unstable_cache } from 'next/cache'
|
||||
import { unstable_cache, cookies } from 'next/cache'
|
||||
import { SupportedLanguage } from './load-translations'
|
||||
|
||||
const SUPPORTED_LANGUAGES = new Set(['en', 'fr', 'es', 'de', 'fa', 'it', 'pt', 'ru', 'zh', 'ja', 'ko', 'ar', 'hi', 'nl', 'pl'])
|
||||
@@ -79,6 +80,16 @@ const getCachedUserLanguage = unstable_cache(
|
||||
* Should be passed from server components that have access to headers().
|
||||
*/
|
||||
export async function detectUserLanguage(browserLanguageHint?: SupportedLanguage | null): Promise<SupportedLanguage> {
|
||||
// 0. Cookie has highest priority — set by the client when user picks a language.
|
||||
// This guarantees server and client agree on the language (no hydration mismatch).
|
||||
try {
|
||||
const cookieStore = await cookies()
|
||||
const cookieLang = cookieStore.get('user-language')?.value
|
||||
if (cookieLang && SUPPORTED_LANGUAGES.has(cookieLang)) {
|
||||
return cookieLang as SupportedLanguage
|
||||
}
|
||||
} catch {}
|
||||
|
||||
const session = await auth()
|
||||
|
||||
if (!session?.user?.id) {
|
||||
|
||||
Reference in New Issue
Block a user