mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-03-20 12:11:28 -07:00
chore: apply remaining workspace formatting and updates
This commit is contained in:
@@ -11,10 +11,18 @@ export function useAnimeLibrary() {
|
||||
let cancelled = false;
|
||||
getStatsClient()
|
||||
.getAnimeLibrary()
|
||||
.then((data) => { if (!cancelled) setAnime(data); })
|
||||
.catch((err: Error) => { if (!cancelled) setError(err.message); })
|
||||
.finally(() => { if (!cancelled) setLoading(false); });
|
||||
return () => { cancelled = true; };
|
||||
.then((data) => {
|
||||
if (!cancelled) setAnime(data);
|
||||
})
|
||||
.catch((err: Error) => {
|
||||
if (!cancelled) setError(err.message);
|
||||
})
|
||||
.finally(() => {
|
||||
if (!cancelled) setLoading(false);
|
||||
});
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, []);
|
||||
|
||||
return { anime, loading, error };
|
||||
|
||||
@@ -57,25 +57,19 @@ export function useExcludedWords() {
|
||||
[excluded],
|
||||
);
|
||||
|
||||
const toggleExclusion = useCallback(
|
||||
(w: ExcludedWord) => {
|
||||
const key = toKey(w);
|
||||
const current = load();
|
||||
if (getKeySet().has(key)) {
|
||||
persist(current.filter(e => toKey(e) !== key));
|
||||
} else {
|
||||
persist([...current, w]);
|
||||
}
|
||||
},
|
||||
[],
|
||||
);
|
||||
const toggleExclusion = useCallback((w: ExcludedWord) => {
|
||||
const key = toKey(w);
|
||||
const current = load();
|
||||
if (getKeySet().has(key)) {
|
||||
persist(current.filter((e) => toKey(e) !== key));
|
||||
} else {
|
||||
persist([...current, w]);
|
||||
}
|
||||
}, []);
|
||||
|
||||
const removeExclusion = useCallback(
|
||||
(w: ExcludedWord) => {
|
||||
persist(load().filter(e => toKey(e) !== toKey(w)));
|
||||
},
|
||||
[],
|
||||
);
|
||||
const removeExclusion = useCallback((w: ExcludedWord) => {
|
||||
persist(load().filter((e) => toKey(e) !== toKey(w)));
|
||||
}, []);
|
||||
|
||||
const clearAll = useCallback(() => persist([]), []);
|
||||
|
||||
|
||||
@@ -11,10 +11,18 @@ export function useStreakCalendar(days = 90) {
|
||||
let cancelled = false;
|
||||
getStatsClient()
|
||||
.getStreakCalendar(days)
|
||||
.then((data) => { if (!cancelled) setCalendar(data); })
|
||||
.catch((err: Error) => { if (!cancelled) setError(err.message); })
|
||||
.finally(() => { if (!cancelled) setLoading(false); });
|
||||
return () => { cancelled = true; };
|
||||
.then((data) => {
|
||||
if (!cancelled) setCalendar(data);
|
||||
})
|
||||
.catch((err: Error) => {
|
||||
if (!cancelled) setError(err.message);
|
||||
})
|
||||
.finally(() => {
|
||||
if (!cancelled) setLoading(false);
|
||||
});
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [days]);
|
||||
|
||||
return { calendar, loading, error };
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { getStatsClient } from './useStatsApi';
|
||||
import type { DailyRollup, MonthlyRollup, EpisodesPerDay, NewAnimePerDay, WatchTimePerAnime, SessionSummary, AnimeLibraryItem } from '../types/stats';
|
||||
import type {
|
||||
DailyRollup,
|
||||
MonthlyRollup,
|
||||
EpisodesPerDay,
|
||||
NewAnimePerDay,
|
||||
WatchTimePerAnime,
|
||||
SessionSummary,
|
||||
AnimeLibraryItem,
|
||||
} from '../types/stats';
|
||||
|
||||
export type TimeRange = '7d' | '30d' | '90d' | 'all';
|
||||
export type GroupBy = 'day' | 'month';
|
||||
@@ -35,9 +43,7 @@ export function useTrends(range: TimeRange, groupBy: GroupBy) {
|
||||
const monthlyLimit = Math.max(1, Math.ceil(limit / 30));
|
||||
|
||||
const rollupFetcher =
|
||||
groupBy === 'month'
|
||||
? client.getMonthlyRollups(monthlyLimit)
|
||||
: client.getDailyRollups(limit);
|
||||
groupBy === 'month' ? client.getMonthlyRollups(monthlyLimit) : client.getDailyRollups(limit);
|
||||
|
||||
Promise.all([
|
||||
rollupFetcher,
|
||||
@@ -47,9 +53,18 @@ export function useTrends(range: TimeRange, groupBy: GroupBy) {
|
||||
client.getSessions(500),
|
||||
client.getAnimeLibrary(),
|
||||
])
|
||||
.then(([rollups, episodesPerDay, newAnimePerDay, watchTimePerAnime, sessions, animeLibrary]) => {
|
||||
setData({ rollups, episodesPerDay, newAnimePerDay, watchTimePerAnime, sessions, animeLibrary });
|
||||
})
|
||||
.then(
|
||||
([rollups, episodesPerDay, newAnimePerDay, watchTimePerAnime, sessions, animeLibrary]) => {
|
||||
setData({
|
||||
rollups,
|
||||
episodesPerDay,
|
||||
newAnimePerDay,
|
||||
watchTimePerAnime,
|
||||
sessions,
|
||||
animeLibrary,
|
||||
});
|
||||
},
|
||||
)
|
||||
.catch((err) => setError(err.message))
|
||||
.finally(() => setLoading(false));
|
||||
}, [range, groupBy]);
|
||||
|
||||
Reference in New Issue
Block a user