perf: memo GridCard, fuse save fns, fix slash tab active color
Some checks failed
CI / Lint, Unit Tests & Build (push) Failing after 1m32s
CI / Deploy production (on server) (push) Has been skipped

This commit is contained in:
Antigravity
2026-06-14 14:06:05 +00:00
parent a8785ed4f1
commit a623454347
120 changed files with 12301 additions and 785 deletions

View File

@@ -110,3 +110,58 @@ export function openCookiePreferences(): void {
if (!isBrowser()) return
window.dispatchEvent(new CustomEvent(OPEN_COOKIE_PREFERENCES_EVENT))
}
/**
* Save consent locally and sync to database for authenticated users.
* This is the preferred method for updating consent from UI components.
*
* Note: For server-side sync, import and call saveCookieConsent action from your component.
*/
export function saveConsentWithSync(analytics: boolean, marketing: boolean = false): ConsentRecord {
const record = setConsent({ analytics, marketing })
// Trigger server-side sync in the background
// The import() is dynamic to avoid "use server" import issues in client code
if (isBrowser()) {
import('@/app/actions/cookie-consent').then(({ saveCookieConsent }) => {
saveCookieConsent(record).catch((err) => {
console.warn('[saveConsentWithSync] Server sync failed (local consent saved):', err)
})
})
}
return record
}
/**
* Load consent preferring DB value when local storage is empty.
* For authenticated users on a new device, this syncs their existing consent.
*
* Returns the consent record that should be used, or null if no preference exists.
*/
export async function loadConsentWithDBSync(): Promise<ConsentRecord | null> {
// First check local storage (fast, always available)
const local = getConsent()
if (local) {
return local // User already has local preference, use it
}
// No local preference — try to load from DB for authenticated users
if (isBrowser()) {
try {
const { getCookieConsentFromDB } = await import('@/app/actions/cookie-consent')
const dbConsent = await getCookieConsentFromDB()
if (dbConsent) {
// Sync DB value to local storage for future use
localStorage.setItem(CONSENT_STORAGE_KEY, JSON.stringify(dbConsent))
writeCookie(dbConsent)
return dbConsent
}
} catch (error) {
console.warn('[loadConsentWithDBSync] Failed to load from DB:', error)
}
}
return null // No preference anywhere
}