immich/web/src/lib/stores/preferences.store.ts

149 lines
3.9 KiB
TypeScript
Raw Normal View History

import { browser } from '$app/environment';
2024-06-07 18:35:05 +02:00
import { Theme, defaultLang } from '$lib/constants';
import { getPreferredLocale } from '$lib/utils/i18n';
import { persisted } from 'svelte-local-storage-store';
import { get } from 'svelte/store';
export interface ThemeSetting {
value: Theme;
system: boolean;
}
export const handleToggleTheme = () => {
const theme = get(colorTheme);
theme.value = theme.value === Theme.DARK ? Theme.LIGHT : Theme.DARK;
colorTheme.set(theme);
};
const initTheme = (): ThemeSetting => {
if (browser && window.matchMedia && !window.matchMedia('(prefers-color-scheme: dark)').matches) {
return { value: Theme.LIGHT, system: false };
}
return { value: Theme.DARK, system: false };
};
const initialTheme = initTheme();
// The 'color-theme' key is also used by app.html to prevent FOUC on page load.
export const colorTheme = persisted<ThemeSetting>('color-theme', initialTheme, {
serializer: {
parse: (text: string): ThemeSetting => {
const parsedText: ThemeSetting = JSON.parse(text);
return Object.values(Theme).includes(parsedText.value) ? parsedText : initTheme();
},
stringify: (object) => JSON.stringify(object),
},
});
// Locale to use for formatting dates, numbers, etc.
export const locale = persisted<string | undefined>('locale', undefined, {
serializer: {
parse: (text) => text,
stringify: (object) => object ?? '',
},
});
const preferredLocale = browser ? getPreferredLocale() : undefined;
export const lang = persisted<string>('lang', preferredLocale || defaultLang.code, {
feat(web): translations (#9854) * First test * Added translation using Weblate (French) * Translated using Weblate (German) Currently translated at 100.0% (4 of 4 strings) Translation: immich/web Translate-URL: http://familie-mach.net/projects/immich/web/de/ * Translated using Weblate (French) Currently translated at 100.0% (4 of 4 strings) Translation: immich/web Translate-URL: http://familie-mach.net/projects/immich/web/fr/ * Further testing * Further testing * Translated using Weblate (German) Currently translated at 100.0% (18 of 18 strings) Translation: immich/web Translate-URL: http://familie-mach.net/projects/immich/web/de/ * Further work * Update string file. * More strings * Automatically changed strings * Add automatically translated german file for testing purposes * Fix merge-face-selector component * Make server stats strings uppercase * Fix uppercase string * Fix some strings in jobs-panel * Fix lower and uppercase strings. Add a few additional string. Fix a few unnecessary replacements * Update german test translations * Fix typo in locales file * Change string keys * Extract more strings * Extract and replace some more strings * Update testtranslationfile * Change translation keys * Fix rebase errors * Fix one more rebase error * Remove german translation file * Co-authored-by: Daniel Dietzler <danieldietzler@users.noreply.github.com> * chore: clean up translations * chore: add new line * fix formatting * chore: fixes * fix: loading and tests --------- Co-authored-by: root <root@Blacki> Co-authored-by: admin <admin@example.com> Co-authored-by: Jason Rasmussen <jrasm91@gmail.com> Co-authored-by: Daniel Dietzler <mail@ddietzler.dev>
2024-06-04 21:53:00 +02:00
serializer: {
parse: (text) => text,
stringify: (object) => object ?? '',
},
});
export interface MapSettings {
allowDarkMode: boolean;
includeArchived: boolean;
onlyFavorites: boolean;
withPartners: boolean;
withSharedAlbums: boolean;
relativeDate: string;
dateAfter: string;
dateBefore: string;
}
export const mapSettings = persisted<MapSettings>('map-settings', {
allowDarkMode: true,
includeArchived: false,
onlyFavorites: false,
withPartners: false,
withSharedAlbums: false,
relativeDate: '',
dateAfter: '',
dateBefore: '',
});
export const videoViewerVolume = persisted<number>('video-viewer-volume', 1, {});
export const videoViewerMuted = persisted<boolean>('video-viewer-muted', false, {});
export const isShowDetail = persisted<boolean>('info-opened', false, {});
export interface AlbumViewSettings {
view: string;
filter: string;
groupBy: string;
groupOrder: string;
sortBy: string;
sortOrder: string;
collapsedGroups: {
// Grouping Option => Array<Group ID>
[group: string]: string[];
};
}
2023-09-27 23:09:54 -04:00
export interface SidebarSettings {
people: boolean;
sharing: boolean;
2023-09-27 23:09:54 -04:00
}
export enum SortOrder {
Asc = 'asc',
Desc = 'desc',
}
export enum AlbumViewMode {
Cover = 'Cover',
List = 'List',
}
export enum AlbumFilter {
All = 'All',
Owned = 'Owned',
Shared = 'Shared',
}
export enum AlbumGroupBy {
None = 'None',
Year = 'Year',
Owner = 'Owner',
}
export enum AlbumSortBy {
Title = 'Title',
ItemCount = 'ItemCount',
DateModified = 'DateModified',
DateCreated = 'DateCreated',
MostRecentPhoto = 'MostRecentPhoto',
OldestPhoto = 'OldestPhoto',
}
export const albumViewSettings = persisted<AlbumViewSettings>('album-view-settings', {
view: AlbumViewMode.Cover,
filter: AlbumFilter.All,
groupBy: AlbumGroupBy.Year,
groupOrder: SortOrder.Desc,
sortBy: AlbumSortBy.MostRecentPhoto,
sortOrder: SortOrder.Desc,
collapsedGroups: {},
});
export const showDeleteModal = persisted<boolean>('delete-confirm-dialog', true, {});
export const alwaysLoadOriginalFile = persisted<boolean>('always-load-original-file', false, {});
export const playVideoThumbnailOnHover = persisted<boolean>('play-video-thumbnail-on-hover', true, {});
export const loopVideo = persisted<boolean>('loop-video', true, {});
export const recentAlbumsDropdown = persisted<boolean>('recent-albums-open', true, {});