-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5a9fcc2
commit ea1f31c
Showing
11 changed files
with
171 additions
and
14 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const DEFAULT_FACETS_SHOWN = 5; | ||
export const DEFAULT_FACET_SORT = 'hits.desc'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export type UserSettings = SettingsObj | undefined; | ||
|
||
interface SettingsObj { | ||
facetSort: { | ||
[dimension: string]: string; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import Cookies from 'js-cookie'; | ||
import { browser } from '$app/environment'; | ||
import type { UserSettings } from '$lib/types/userSettings'; | ||
|
||
export function saveUserSetting(namespace: 'facetSort', value: { [dimension: string]: string }) { | ||
if (browser) { | ||
const userSettings = Cookies.get('userSettings'); | ||
let newSettings; | ||
|
||
if (userSettings) { | ||
try { | ||
const parsedSettings = JSON.parse(userSettings) as UserSettings; | ||
if (parsedSettings) { | ||
newSettings = { | ||
...parsedSettings, | ||
[namespace]: { | ||
...(namespace in parsedSettings && parsedSettings[namespace]), | ||
...value | ||
} | ||
}; | ||
} | ||
} catch (e) { | ||
console.warn(e); | ||
} | ||
} else { | ||
newSettings = { [namespace]: value }; | ||
} | ||
Cookies.set('userSettings', JSON.stringify(newSettings)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { UserSettings } from '$lib/types/userSettings.js'; | ||
|
||
export async function load({ cookies }) { | ||
let userSettings: UserSettings; | ||
const settingsCookie = cookies.get('userSettings'); | ||
if (settingsCookie) { | ||
try { | ||
userSettings = JSON.parse(settingsCookie); | ||
} catch (e) { | ||
console.warn('Failed to parse user settings', e); | ||
} | ||
} | ||
return { | ||
userSettings | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import { getTranslator } from '$lib/i18n/index.js'; | ||
import { getSupportedLocale, defaultLocale } from '$lib/i18n/locales'; | ||
|
||
export async function load({ params }) { | ||
export async function load({ params, data }) { | ||
const locale = getSupportedLocale(params?.lang); // will use default locale if no lang param | ||
const t = await getTranslator(locale); | ||
const base = locale === defaultLocale ? '/' : `/${locale}/`; | ||
return { locale, t, base }; | ||
const userSettings = data.userSettings; | ||
return { locale, t, base, userSettings }; | ||
} |