2023-08-08 09:39:51 -05:00
< script lang = "ts" >
import SettingSelect from '$lib/components/admin-page/settings/setting-select.svelte';
2023-09-03 02:21:51 -04:00
import { api , Colorspace , SystemConfigThumbnailDto } from '@api';
2023-08-08 09:39:51 -05:00
import { fade } from 'svelte/transition';
import { isEqual } from 'lodash-es';
import SettingButtonsRow from '$lib/components/admin-page/settings/setting-buttons-row.svelte';
import {
notificationController,
NotificationType,
} from '$lib/components/shared-components/notification/notification';
2023-09-03 02:21:51 -04:00
import SettingInputField, { SettingInputFieldType } from '../setting-input-field.svelte';
import SettingSwitch from '../setting-switch.svelte';
2023-08-08 09:39:51 -05:00
export let thumbnailConfig: SystemConfigThumbnailDto; // this is the config that is being edited
2023-08-25 19:44:52 +02:00
export let disabled = false;
2023-08-08 09:39:51 -05:00
let savedConfig: SystemConfigThumbnailDto;
let defaultConfig: SystemConfigThumbnailDto;
async function getConfigs() {
[savedConfig, defaultConfig] = await Promise.all([
api.systemConfigApi.getConfig().then((res) => res.data.thumbnail),
2023-11-03 21:33:15 -04:00
api.systemConfigApi.getConfigDefaults().then((res) => res.data.thumbnail),
2023-08-08 09:39:51 -05:00
]);
}
async function reset() {
const { data : resetConfig } = await api.systemConfigApi.getConfig();
thumbnailConfig = { ... resetConfig . thumbnail } ;
savedConfig = { ... resetConfig . thumbnail } ;
notificationController.show({
message: 'Reset thumbnail settings to the recent saved settings',
type: NotificationType.Info,
});
}
async function resetToDefault() {
2023-11-03 21:33:15 -04:00
const { data : configs } = await api.systemConfigApi.getConfigDefaults();
2023-08-08 09:39:51 -05:00
thumbnailConfig = { ... configs . thumbnail } ;
defaultConfig = { ... configs . thumbnail } ;
notificationController.show({
message: 'Reset thumbnail settings to default',
type: NotificationType.Info,
});
}
async function saveSetting() {
try {
const { data : configs } = await api.systemConfigApi.getConfig();
const result = await api.systemConfigApi.updateConfig({
systemConfigDto: {
...configs,
thumbnail: thumbnailConfig,
},
});
thumbnailConfig = { ... result . data . thumbnail } ;
savedConfig = { ... result . data . thumbnail } ;
notificationController.show({
message: 'Thumbnail settings saved',
type: NotificationType.Info,
});
} catch (e) {
console.error('Error [thumbnail-settings] [saveSetting]', e);
notificationController.show({
message: 'Unable to save settings',
type: NotificationType.Error,
});
}
}
< / script >
< div >
{ #await getConfigs () then }
< div in:fade = {{ duration : 500 }} >
< form autocomplete = "off" on:submit | preventDefault >
< div class = "ml-4 mt-4 flex flex-col gap-4" >
< SettingSelect
2023-08-16 20:25:07 +02:00
label="SMALL THUMBNAIL RESOLUTION"
desc="Used when viewing groups of photos (main timeline, album view, etc.). Higher resolutions can preserve more detail but take longer to encode, have larger file sizes, and can reduce app responsiveness."
2023-08-08 09:39:51 -05:00
number
bind:value={ thumbnailConfig . webpSize }
options={[
{ value : 1080 , text : '1080p' } ,
{ value : 720 , text : '720p' } ,
{ value : 480 , text : '480p' } ,
{ value : 250 , text : '250p' } ,
2023-11-17 12:25:35 -08:00
{ value : 200 , text : '200p' } ,
2023-08-08 09:39:51 -05:00
]}
name="resolution"
2023-09-03 02:21:51 -04:00
isEdited={ thumbnailConfig . webpSize !== savedConfig . webpSize }
2023-08-25 19:44:52 +02:00
{ disabled }
2023-08-08 09:39:51 -05:00
/>
< SettingSelect
2023-08-16 20:25:07 +02:00
label="LARGE THUMBNAIL RESOLUTION"
desc="Used when viewing a single photo and for machine learning. Higher resolutions can preserve more detail but take longer to encode, have larger file sizes, and can reduce app responsiveness."
2023-08-08 09:39:51 -05:00
number
bind:value={ thumbnailConfig . jpegSize }
options={[
{ value : 2160 , text : '4K' } ,
{ value : 1440 , text : '1440p' } ,
2023-11-17 12:25:35 -08:00
{ value : 1080 , text : '1080p' } ,
{ value : 720 , text : '720p' } ,
2023-08-08 09:39:51 -05:00
]}
name="resolution"
2023-09-03 02:21:51 -04:00
isEdited={ thumbnailConfig . jpegSize !== savedConfig . jpegSize }
2023-08-25 19:44:52 +02:00
{ disabled }
2023-08-08 09:39:51 -05:00
/>
2023-09-03 02:21:51 -04:00
< SettingInputField
inputType={ SettingInputFieldType . NUMBER }
label="QUALITY"
desc="Thumbnail quality from 1-100. Higher is better for quality but produces larger files."
bind:value={ thumbnailConfig . quality }
isEdited={ thumbnailConfig . quality !== savedConfig . quality }
/>
< SettingSwitch
title="PREFER WIDE GAMUT"
subtitle="Use Display P3 for thumbnails. This better preserves the vibrance of images with wide colorspaces, but images may appear differently on old devices with an old browser version. sRGB images are kept as sRGB to avoid color shifts."
checked={ thumbnailConfig . colorspace === Colorspace . P3 }
on:toggle={( e ) => ( thumbnailConfig . colorspace = e . detail ? Colorspace.P3 : Colorspace.Srgb )}
isEdited={ thumbnailConfig . colorspace !== savedConfig . colorspace }
/>
2023-08-08 09:39:51 -05:00
< / div >
< div class = "ml-4" >
< SettingButtonsRow
on:reset={ reset }
on:save={ saveSetting }
on:reset-to-default={ resetToDefault }
showResetToDefault={ ! isEqual ( savedConfig , defaultConfig )}
2023-08-25 19:44:52 +02:00
{ disabled }
2023-08-08 09:39:51 -05:00
/>
< / div >
< / form >
< / div >
{ /await }
< / div >