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

150 lines
3.6 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-persisted-store';
export interface ThemeSetting {
value: Theme;
system: boolean;
}
// Locale to use for formatting dates, numbers, etc.
export const locale = persisted<string | undefined>('locale', 'default', {
serializer: {
parse: (text) => text || 'default',
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;
}
2025-01-16 10:05:14 -05:00
const defaultMapSettings = {
allowDarkMode: true,
includeArchived: false,
onlyFavorites: false,
withPartners: false,
withSharedAlbums: false,
relativeDate: '',
dateAfter: '',
dateBefore: '',
2025-01-16 10:05:14 -05:00
};
const persistedObject = <T>(key: string, defaults: T) =>
persisted<T>(key, defaults, {
serializer: {
parse: (text) => ({ ...defaultMapSettings, ...JSON.parse(text ?? null) }),
stringify: JSON.stringify,
},
});
export const mapSettings = persistedObject<MapSettings>('map-settings', defaultMapSettings);
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[];
};
}
export interface PlacesViewSettings {
groupBy: 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 enum PlacesGroupBy {
None = 'None',
Country = 'Country',
}
export const placesViewSettings = persisted<PlacesViewSettings>('places-view-settings', {
groupBy: PlacesGroupBy.None,
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, {});