restructure files
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import { _user_preferences } from '$lib/preferences/_private';
|
||||
import type { UserPreferences } from '$lib/types';
|
||||
import clamp from 'just-clamp';
|
||||
import { save } from './local-storage';
|
||||
|
||||
function clamp_preferences(prefs: UserPreferences) {
|
||||
return {
|
||||
playback_rate: clamp(prefs.playback_rate, 0.5, 5),
|
||||
volume: clamp(prefs.volume, 0, 1),
|
||||
};
|
||||
}
|
||||
|
||||
export function edit_preference(prefs: Partial<UserPreferences>) {
|
||||
_user_preferences.update((prev) => clamp_preferences({ ...prev, ...prefs }));
|
||||
save();
|
||||
}
|
||||
@@ -1,52 +1,12 @@
|
||||
import { browser } from '$app/environment';
|
||||
import { edit_preference } from '$lib/preferences/edit';
|
||||
import { _default_user_preferences, _user_preferences } from '$lib/preferences/_private';
|
||||
import type { UserPreferences } from '$lib/types';
|
||||
import { info, warn } from '$lib/utility/package/log';
|
||||
import clamp from 'just-clamp';
|
||||
|
||||
function clamp_preferences(prefs: UserPreferences) {
|
||||
return {
|
||||
playback_rate: clamp(prefs.playback_rate, 0.5, 5),
|
||||
volume: clamp(prefs.volume, 0, 1),
|
||||
};
|
||||
}
|
||||
const USER_PREFERENCE_KEY = 'USER_PREFERENCE' as const;
|
||||
|
||||
function set(prefs: Partial<UserPreferences>) {
|
||||
_user_preferences.update((prev) => clamp_preferences({ ...prev, ...prefs }));
|
||||
save();
|
||||
}
|
||||
function save() {
|
||||
if (!browser || !localStorage) {
|
||||
warn('localStorage not available, skipping save');
|
||||
return;
|
||||
}
|
||||
return _user_preferences.subscribe((prefs) => {
|
||||
info(`Saving user preferences to localStorage`, prefs);
|
||||
localStorage.setItem(USER_PREFERENCE_KEY, JSON.stringify(prefs));
|
||||
})();
|
||||
}
|
||||
import { load, save } from './local-storage';
|
||||
|
||||
export const podcast_preferences = {
|
||||
subscribe: _user_preferences.subscribe,
|
||||
set,
|
||||
edit: edit_preference,
|
||||
load,
|
||||
save,
|
||||
load() {
|
||||
if (!browser || !localStorage) {
|
||||
warn('localStorage not available, skipping load');
|
||||
return;
|
||||
}
|
||||
const data = localStorage.getItem(USER_PREFERENCE_KEY);
|
||||
|
||||
if (!data) {
|
||||
info('No saved user preferences found');
|
||||
return;
|
||||
}
|
||||
|
||||
const preferences = JSON.parse(data) as UserPreferences;
|
||||
set(preferences);
|
||||
info(`Loaded user preferences from localStorage`, preferences);
|
||||
},
|
||||
clear() {
|
||||
_user_preferences.set(_default_user_preferences);
|
||||
save();
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import { browser } from '$app/environment';
|
||||
import { edit_preference } from '$lib/preferences/edit';
|
||||
import { _user_preferences } from '$lib/preferences/_private';
|
||||
import type { UserPreferences } from '$lib/types';
|
||||
import { info, warn } from '$lib/utility/package/log';
|
||||
|
||||
const USER_PREFERENCE_KEY = 'USER_PREFERENCE' as const;
|
||||
|
||||
export function save() {
|
||||
if (!browser || !localStorage) {
|
||||
warn('localStorage not available, skipping save');
|
||||
return;
|
||||
}
|
||||
return _user_preferences.subscribe((prefs) => {
|
||||
info(`Saving user preferences to localStorage`, prefs);
|
||||
localStorage.setItem(USER_PREFERENCE_KEY, JSON.stringify(prefs));
|
||||
})();
|
||||
}
|
||||
|
||||
export function load() {
|
||||
if (!browser || !localStorage) {
|
||||
warn('localStorage not available, skipping load');
|
||||
return;
|
||||
}
|
||||
const data = localStorage.getItem(USER_PREFERENCE_KEY);
|
||||
|
||||
if (!data) {
|
||||
info('No saved user preferences found');
|
||||
return;
|
||||
}
|
||||
|
||||
const preferences = JSON.parse(data) as UserPreferences;
|
||||
edit_preference(preferences);
|
||||
|
||||
info(`Loaded user preferences from localStorage`, preferences);
|
||||
}
|
||||
@@ -1,27 +1,9 @@
|
||||
import { browser } from '$app/environment';
|
||||
import { _current_time, _src } from '$lib/audio/_private';
|
||||
import { _episode_progress_map } from '$lib/progress/_private';
|
||||
import type { AudioLoadOptions } from '$lib/types';
|
||||
import { error, info, warn } from '$lib/utility/package/log';
|
||||
import { info } from '$lib/utility/package/log';
|
||||
import { get } from 'svelte/store';
|
||||
|
||||
type SavedEpisodeProgress = { src: string; current_time: number };
|
||||
const EPISODE_PROGRESS_KEY = 'EPISODE_PROGRESS' as const;
|
||||
|
||||
function save_all() {
|
||||
if (!browser || !localStorage) {
|
||||
warn('localStorage not available, skipping save');
|
||||
return;
|
||||
}
|
||||
const items = [..._episode_progress_map];
|
||||
|
||||
const episodes = items.reduce((prev, [src, current_time]) => {
|
||||
return [...prev, { src, current_time }];
|
||||
}, [] as SavedEpisodeProgress[]);
|
||||
|
||||
info(`Saving progress for ${episodes.length} episodes to localStorage`, episodes);
|
||||
localStorage.setItem(EPISODE_PROGRESS_KEY, JSON.stringify(episodes));
|
||||
}
|
||||
import { load_all, save_all } from './local-storage';
|
||||
|
||||
export const podcast_progress = {
|
||||
episodes: {
|
||||
@@ -49,31 +31,7 @@ export const podcast_progress = {
|
||||
return { start_at: start_at };
|
||||
},
|
||||
save_all,
|
||||
|
||||
load_all() {
|
||||
if (!browser || !localStorage) {
|
||||
warn('localStorage not available, skipping load');
|
||||
return;
|
||||
}
|
||||
const data = localStorage.getItem(EPISODE_PROGRESS_KEY);
|
||||
|
||||
if (!data) {
|
||||
info('No saved episode progress found');
|
||||
return;
|
||||
}
|
||||
|
||||
const episodes = JSON.parse(data) as SavedEpisodeProgress[];
|
||||
|
||||
try {
|
||||
episodes.forEach(({ src, current_time }) => {
|
||||
podcast_progress.episodes.set(src, current_time);
|
||||
});
|
||||
info(`Loaded ${_episode_progress_map.size} episodes progress from localStorage`);
|
||||
} catch (e) {
|
||||
error('Error loading episode progress', e);
|
||||
return;
|
||||
}
|
||||
},
|
||||
load_all,
|
||||
clear_all() {
|
||||
_episode_progress_map.clear();
|
||||
save_all();
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
import { browser } from '$app/environment';
|
||||
import { _episode_progress_map } from '$lib/progress/_private';
|
||||
import { error, info, warn } from '$lib/utility/package/log';
|
||||
|
||||
type SavedEpisodeProgress = { src: string; current_time: number };
|
||||
const EPISODE_PROGRESS_KEY = 'EPISODE_PROGRESS' as const;
|
||||
|
||||
export function save_all() {
|
||||
if (!browser || !localStorage) {
|
||||
warn('localStorage not available, skipping save');
|
||||
return;
|
||||
}
|
||||
const items = [..._episode_progress_map];
|
||||
|
||||
const episodes = items.reduce((prev, [src, current_time]) => {
|
||||
return [...prev, { src, current_time }];
|
||||
}, [] as SavedEpisodeProgress[]);
|
||||
|
||||
info(`Saving progress for ${episodes.length} episodes to localStorage`, episodes);
|
||||
localStorage.setItem(EPISODE_PROGRESS_KEY, JSON.stringify(episodes));
|
||||
}
|
||||
|
||||
export function load_all() {
|
||||
if (!browser || !localStorage) {
|
||||
warn('localStorage not available, skipping load');
|
||||
return;
|
||||
}
|
||||
const data = localStorage.getItem(EPISODE_PROGRESS_KEY);
|
||||
|
||||
if (!data) {
|
||||
info('No saved episode progress found');
|
||||
return;
|
||||
}
|
||||
|
||||
const episodes = JSON.parse(data) as SavedEpisodeProgress[];
|
||||
|
||||
try {
|
||||
episodes.forEach(({ src, current_time }) => {
|
||||
_episode_progress_map.set(src, current_time);
|
||||
});
|
||||
info(`Loaded ${_episode_progress_map.size} episodes progress from localStorage`);
|
||||
} catch (e) {
|
||||
error('Error loading episode progress', e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user