cleaning up code
This commit is contained in:
@@ -35,6 +35,7 @@ const defaultSettings: AppSettings = {
|
||||
const defaultPreferences: UserPreferences = {
|
||||
showExplicit: false,
|
||||
autoDownload: false,
|
||||
autoJumpToPlayer: true,
|
||||
};
|
||||
|
||||
const defaultState: AppState = {
|
||||
@@ -43,7 +44,7 @@ const defaultState: AppState = {
|
||||
customTheme: DEFAULT_THEME,
|
||||
};
|
||||
|
||||
export function createAppStore() {
|
||||
function createAppStore() {
|
||||
// Start with defaults; async load will update once ready
|
||||
const [state, setState] = createSignal<AppState>(defaultState);
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ const defaultNavState: AudioNavState = {
|
||||
};
|
||||
|
||||
/** Create audio navigation store */
|
||||
export function createAudioNavStore() {
|
||||
function createAudioNavStore() {
|
||||
const [navState, setNavState] = createSignal<AudioNavState>(defaultNavState);
|
||||
|
||||
/** Persist current navigation state to file (fire-and-forget) */
|
||||
|
||||
@@ -127,7 +127,6 @@ export function createDiscoverStore() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Build the podcast list from the manifest entries
|
||||
const fetched = manifest.podcasts.map(entryToPodcast);
|
||||
cachedAt = now;
|
||||
setPodcasts(fetched);
|
||||
@@ -173,7 +172,6 @@ export function createDiscoverStore() {
|
||||
const unsubscribe = (podcastId: string) => {
|
||||
const podcast = podcasts().find((p) => p.id === podcastId);
|
||||
if (podcast) {
|
||||
// Remove the feed from the feed store
|
||||
const feedStore = useFeedStore();
|
||||
feedStore.removeFeedByUrl(podcast.feedUrl);
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ interface QueueItem {
|
||||
}
|
||||
|
||||
/** Create download store */
|
||||
export function createDownloadStore() {
|
||||
function createDownloadStore() {
|
||||
const [downloads, setDownloads] = createSignal<
|
||||
Map<string, DownloadedEpisode>
|
||||
>(new Map());
|
||||
@@ -48,7 +48,6 @@ export function createDownloadStore() {
|
||||
/** Active AbortControllers keyed by episodeId */
|
||||
const abortControllers = new Map<string, AbortController>();
|
||||
|
||||
// Load persisted downloads on init
|
||||
(async () => {
|
||||
const loaded = await loadDownloads();
|
||||
if (loaded.size > 0) setDownloads(loaded);
|
||||
@@ -153,7 +152,6 @@ export function createDownloadStore() {
|
||||
const slotsAvailable = MAX_CONCURRENT - current;
|
||||
const toStart = q.slice(0, slotsAvailable);
|
||||
|
||||
// Remove started items from queue
|
||||
if (toStart.length > 0) {
|
||||
setQueue((prev) => prev.slice(toStart.length));
|
||||
}
|
||||
@@ -250,7 +248,6 @@ export function createDownloadStore() {
|
||||
return; // Already downloading or queued
|
||||
}
|
||||
|
||||
// Create download entry
|
||||
const entry: DownloadedEpisode = {
|
||||
episodeId: episode.id,
|
||||
feedId,
|
||||
@@ -269,7 +266,6 @@ export function createDownloadStore() {
|
||||
return next;
|
||||
});
|
||||
|
||||
// Add to queue
|
||||
const queueItem: QueueItem = {
|
||||
episodeId: episode.id,
|
||||
feedId,
|
||||
@@ -291,10 +287,8 @@ export function createDownloadStore() {
|
||||
abortControllers.delete(episodeId);
|
||||
}
|
||||
|
||||
// Remove from queue
|
||||
setQueue((prev) => prev.filter((q) => q.episodeId !== episodeId));
|
||||
|
||||
// Update status
|
||||
updateDownload(episodeId, {
|
||||
status: DownloadStatus.NONE,
|
||||
progress: 0,
|
||||
|
||||
@@ -43,7 +43,7 @@ function saveSources(sources: PodcastSource[]): void {
|
||||
}
|
||||
|
||||
/** Create feed store */
|
||||
export function createFeedStore() {
|
||||
function createFeedStore() {
|
||||
const [feeds, setFeeds] = createSignal<Feed[]>([]);
|
||||
const [sources, setSources] = createSignal<PodcastSource[]>([
|
||||
...DEFAULT_SOURCES,
|
||||
@@ -62,22 +62,18 @@ export function createFeedStore() {
|
||||
let result = [...feeds()];
|
||||
const f = filter();
|
||||
|
||||
// Filter by visibility
|
||||
if (f.visibility && f.visibility !== "all") {
|
||||
result = result.filter((feed) => feed.visibility === f.visibility);
|
||||
}
|
||||
|
||||
// Filter by source
|
||||
if (f.sourceId) {
|
||||
result = result.filter((feed) => feed.sourceId === f.sourceId);
|
||||
}
|
||||
|
||||
// Filter by pinned
|
||||
if (f.pinnedOnly) {
|
||||
result = result.filter((feed) => feed.isPinned);
|
||||
}
|
||||
|
||||
// Filter by search query
|
||||
if (f.searchQuery) {
|
||||
const query = f.searchQuery.toLowerCase();
|
||||
result = result.filter(
|
||||
@@ -88,7 +84,6 @@ export function createFeedStore() {
|
||||
);
|
||||
}
|
||||
|
||||
// Sort by selected field
|
||||
const sortDir = f.sortDirection === "asc" ? 1 : -1;
|
||||
result.sort((a, b) => {
|
||||
switch (f.sortBy) {
|
||||
@@ -111,7 +106,6 @@ export function createFeedStore() {
|
||||
}
|
||||
});
|
||||
|
||||
// Pinned feeds always first
|
||||
result.sort((a, b) => {
|
||||
if (a.isPinned && !b.isPinned) return -1;
|
||||
if (!a.isPinned && b.isPinned) return 1;
|
||||
@@ -224,25 +218,21 @@ export function createFeedStore() {
|
||||
newEpisodes: Episode[],
|
||||
count: number,
|
||||
) => {
|
||||
try {
|
||||
const dlStore = useDownloadStore();
|
||||
// Sort by pubDate descending (newest first)
|
||||
const sorted = [...newEpisodes].sort(
|
||||
(a, b) => b.pubDate.getTime() - a.pubDate.getTime(),
|
||||
);
|
||||
// count = 0 means download all new episodes
|
||||
const toDownload = count > 0 ? sorted.slice(0, count) : sorted;
|
||||
for (const ep of toDownload) {
|
||||
const status = dlStore.getDownloadStatus(ep.id);
|
||||
if (
|
||||
status === DownloadStatus.NONE ||
|
||||
status === DownloadStatus.FAILED
|
||||
) {
|
||||
dlStore.startDownload(ep, feedId);
|
||||
}
|
||||
const dlStore = useDownloadStore();
|
||||
// Sort by pubDate descending (newest first)
|
||||
const sorted = [...newEpisodes].sort(
|
||||
(a, b) => b.pubDate.getTime() - a.pubDate.getTime(),
|
||||
);
|
||||
// count = 0 means download all new episodes
|
||||
const toDownload = count > 0 ? sorted.slice(0, count) : sorted;
|
||||
for (const ep of toDownload) {
|
||||
const status = dlStore.getDownloadStatus(ep.id);
|
||||
if (
|
||||
status === DownloadStatus.NONE ||
|
||||
status === DownloadStatus.FAILED
|
||||
) {
|
||||
dlStore.startDownload(ep, feedId);
|
||||
}
|
||||
} catch {
|
||||
// Download store may not be available yet
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -80,7 +80,6 @@ export function createSearchStore() {
|
||||
setIsSearching(true);
|
||||
setError(null);
|
||||
|
||||
// Add to history
|
||||
addToHistory(q);
|
||||
|
||||
try {
|
||||
@@ -122,7 +121,6 @@ export function createSearchStore() {
|
||||
/** Add query to history */
|
||||
const addToHistory = (q: string) => {
|
||||
setHistory((prev) => {
|
||||
// Remove duplicates and add to front
|
||||
const filtered = prev.filter((h) => h.toLowerCase() !== q.toLowerCase());
|
||||
const updated = [q, ...filtered].slice(0, MAX_HISTORY);
|
||||
saveHistory(updated);
|
||||
|
||||
Reference in New Issue
Block a user