Add volume settings
This commit is contained in:
@@ -25,26 +25,6 @@ export type ZoomModes =
|
||||
| 'keepZoom'
|
||||
| 'keepZoomStart';
|
||||
|
||||
export type Settings = {
|
||||
rightToLeft: boolean;
|
||||
singlePageView: boolean;
|
||||
textEditable: boolean;
|
||||
textBoxBorders: boolean;
|
||||
displayOCR: boolean;
|
||||
boldFont: boolean;
|
||||
pageNum: boolean;
|
||||
charCount: boolean;
|
||||
hasCover: boolean;
|
||||
mobile: boolean;
|
||||
backgroundColor: string;
|
||||
swipeThreshold: number;
|
||||
fontSize: FontSize;
|
||||
zoomDefault: ZoomModes;
|
||||
ankiConnectSettings: AnkiConnectSettings;
|
||||
};
|
||||
|
||||
export type SettingsKey = keyof Settings;
|
||||
|
||||
export type AnkiConnectSettings = {
|
||||
enabled: boolean;
|
||||
pictureField: string;
|
||||
@@ -54,12 +34,35 @@ export type AnkiConnectSettings = {
|
||||
grabSentence: boolean;
|
||||
}
|
||||
|
||||
export type VolumeDefaults = {
|
||||
rightToLeft: boolean;
|
||||
singlePageView: boolean;
|
||||
hasCover: boolean;
|
||||
}
|
||||
|
||||
export type Settings = {
|
||||
textEditable: boolean;
|
||||
textBoxBorders: boolean;
|
||||
displayOCR: boolean;
|
||||
boldFont: boolean;
|
||||
pageNum: boolean;
|
||||
charCount: boolean;
|
||||
mobile: boolean;
|
||||
backgroundColor: string;
|
||||
swipeThreshold: number;
|
||||
fontSize: FontSize;
|
||||
zoomDefault: ZoomModes;
|
||||
volumeDefaults: VolumeDefaults;
|
||||
ankiConnectSettings: AnkiConnectSettings;
|
||||
};
|
||||
|
||||
export type SettingsKey = keyof Settings;
|
||||
|
||||
export type AnkiSettingsKey = keyof AnkiConnectSettings;
|
||||
|
||||
export type VolumeDefaultsKey = keyof VolumeDefaults;
|
||||
|
||||
const defaultSettings: Settings = {
|
||||
rightToLeft: true,
|
||||
singlePageView: false,
|
||||
hasCover: false,
|
||||
displayOCR: true,
|
||||
textEditable: false,
|
||||
textBoxBorders: false,
|
||||
@@ -71,6 +74,11 @@ const defaultSettings: Settings = {
|
||||
swipeThreshold: 50,
|
||||
fontSize: 'auto',
|
||||
zoomDefault: 'zoomFitToScreen',
|
||||
volumeDefaults: {
|
||||
singlePageView: false,
|
||||
rightToLeft: true,
|
||||
hasCover: false
|
||||
},
|
||||
ankiConnectSettings: {
|
||||
enabled: false,
|
||||
cropImage: false,
|
||||
@@ -120,7 +128,22 @@ export function updateSetting(key: SettingsKey, value: any) {
|
||||
}
|
||||
};
|
||||
});
|
||||
zoomDefault();
|
||||
}
|
||||
|
||||
export function updateVolumeDefaults(key: VolumeDefaultsKey, value: any) {
|
||||
profiles.update((profiles) => {
|
||||
return {
|
||||
...profiles,
|
||||
[get(currentProfile)]: {
|
||||
...profiles[get(currentProfile)],
|
||||
volumeDefaults: {
|
||||
...profiles[get(currentProfile)].volumeDefaults,
|
||||
[key]: value
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
export function updateAnkiSetting(key: AnkiSettingsKey, value: any) {
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
import { browser } from '$app/environment';
|
||||
import { derived, get, writable } from 'svelte/store';
|
||||
import { settings } from './settings';
|
||||
import { zoomDefault } from '$lib/panzoom';
|
||||
|
||||
type VolumeSettings = {
|
||||
export type VolumeSettings = {
|
||||
rightToLeft: boolean;
|
||||
singlePageView: boolean;
|
||||
hasCover: boolean;
|
||||
}
|
||||
|
||||
export type VolumeSettingsKey = keyof VolumeSettings;
|
||||
|
||||
type Progress = Record<string, number> | undefined;
|
||||
|
||||
type VolumeData = {
|
||||
@@ -26,7 +29,7 @@ const initial: Volumes = stored && browser ? JSON.parse(stored) : undefined;
|
||||
export const volumes = writable<Volumes>(initial);
|
||||
|
||||
export function initializeVolume(volume: string) {
|
||||
const { hasCover, rightToLeft, singlePageView } = get(settings)
|
||||
const { hasCover, rightToLeft, singlePageView } = get(settings).volumeDefaults
|
||||
volumes.update((prev) => {
|
||||
return {
|
||||
...prev,
|
||||
@@ -86,3 +89,31 @@ export const progress = derived(volumes, ($volumes) => {
|
||||
|
||||
return progress
|
||||
})
|
||||
|
||||
export const volumeSettings = derived(volumes, ($volumes) => {
|
||||
const settings: Record<string, VolumeSettings> = {}
|
||||
|
||||
if ($volumes) {
|
||||
Object.keys($volumes).forEach((key) => {
|
||||
settings[key] = $volumes[key].settings
|
||||
});
|
||||
}
|
||||
|
||||
return settings
|
||||
})
|
||||
|
||||
export function updateVolumeSetting(volume: string, key: VolumeSettingsKey, value: any) {
|
||||
volumes.update((prev) => {
|
||||
return {
|
||||
...prev,
|
||||
[volume]: {
|
||||
...prev[volume],
|
||||
settings: {
|
||||
...prev[volume].settings,
|
||||
[key]: value
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
zoomDefault();
|
||||
}
|
||||
Reference in New Issue
Block a user