|
|
|
@ -2,7 +2,6 @@ |
|
|
|
import { useAuthSession } from '../composables/useAuthSession' |
|
|
|
import { |
|
|
|
publicHomeLayoutModeKey, |
|
|
|
publicHomeLayoutStorageKey, |
|
|
|
type PublicHomeLayoutMode, |
|
|
|
} from '../composables/usePublicHomeLayout' |
|
|
|
import { unwrapApiBody, type ApiResponse } from '../utils/http/factory' |
|
|
|
@ -50,35 +49,41 @@ const headerBrandIconUrl = computed(() => |
|
|
|
profileSlug.value ? publicHomeHeader.value?.iconUrl ?? null : null, |
|
|
|
) |
|
|
|
|
|
|
|
type LayoutBySlug = Record<string, PublicHomeLayoutMode> |
|
|
|
|
|
|
|
const layoutBySlug = useCookie<LayoutBySlug>('public_home_layout', { |
|
|
|
default: () => ({}), |
|
|
|
maxAge: 60 * 60 * 24 * 400, |
|
|
|
sameSite: 'lax', |
|
|
|
}) |
|
|
|
|
|
|
|
function cookieModeForSlug(slug: string): PublicHomeLayoutMode { |
|
|
|
const m = layoutBySlug.value[slug] |
|
|
|
return m === 'detailed' || m === 'showcase' ? m : 'showcase' |
|
|
|
} |
|
|
|
|
|
|
|
const publicLayoutMode = ref<PublicHomeLayoutMode>('showcase') |
|
|
|
provide(publicHomeLayoutModeKey, publicLayoutMode) |
|
|
|
|
|
|
|
function syncModeFromStorage() { |
|
|
|
if (!import.meta.client) { |
|
|
|
return |
|
|
|
} |
|
|
|
function syncModeFromCookie() { |
|
|
|
if (!showPublicLayoutToggle.value || !profileSlug.value) { |
|
|
|
return |
|
|
|
} |
|
|
|
const raw = localStorage.getItem(publicHomeLayoutStorageKey(profileSlug.value)) |
|
|
|
publicLayoutMode.value = raw === 'detailed' || raw === 'showcase' ? raw : 'showcase' |
|
|
|
publicLayoutMode.value = cookieModeForSlug(profileSlug.value) |
|
|
|
} |
|
|
|
|
|
|
|
onMounted(() => { |
|
|
|
refresh().catch(() => {}) |
|
|
|
syncModeFromStorage() |
|
|
|
}) |
|
|
|
|
|
|
|
watch([profileSlug, showPublicLayoutToggle], syncModeFromStorage) |
|
|
|
syncModeFromCookie() |
|
|
|
watch([profileSlug, showPublicLayoutToggle, layoutBySlug], syncModeFromCookie) |
|
|
|
|
|
|
|
watch(publicLayoutMode, (m) => { |
|
|
|
if (!import.meta.client) { |
|
|
|
return |
|
|
|
} |
|
|
|
if (!showPublicLayoutToggle.value || !profileSlug.value) { |
|
|
|
return |
|
|
|
} |
|
|
|
localStorage.setItem(publicHomeLayoutStorageKey(profileSlug.value), m) |
|
|
|
layoutBySlug.value = { ...layoutBySlug.value, [profileSlug.value]: m } |
|
|
|
}) |
|
|
|
|
|
|
|
onMounted(() => { |
|
|
|
refresh().catch(() => {}) |
|
|
|
}) |
|
|
|
</script> |
|
|
|
|
|
|
|
|