mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-08-12 13:55:51 -07:00
684ab9eaff
- Collapse animation-burst subtitle lines (karaoke OPs, animated signs) at ingest time using the same dedup rules the subtitle sidebar already applies, so repeated frames no longer flood "Top Repeated Words" - Add retroactive cleanup for stats already affected: a "Duplicates" scanner/cleaner in the Vocabulary tab and `subminer stats cleanup --duplicate-lines` (`--dry-run`, `--lookback-days`) on the CLI - Only subtitle lines and the vocabulary counts they feed are touched; watch time and lines-seen totals are left as recorded
56 lines
1.8 KiB
TypeScript
56 lines
1.8 KiB
TypeScript
import { useState, useEffect, useCallback } from 'react';
|
|
import { getStatsClient } from './useStatsApi';
|
|
import type { VocabularyEntry, KanjiEntry } from '../types/stats';
|
|
|
|
export function useVocabulary() {
|
|
const [words, setWords] = useState<VocabularyEntry[]>([]);
|
|
const [kanji, setKanji] = useState<KanjiEntry[]>([]);
|
|
const [knownWords, setKnownWords] = useState<Set<string>>(new Set());
|
|
const [loading, setLoading] = useState(true);
|
|
const [error, setError] = useState<string | null>(null);
|
|
// Bumped by `reload` after maintenance rewrites the vocabulary tables.
|
|
const [reloadToken, setReloadToken] = useState(0);
|
|
const reload = useCallback(() => setReloadToken((token) => token + 1), []);
|
|
|
|
useEffect(() => {
|
|
let cancelled = false;
|
|
setLoading(true);
|
|
setError(null);
|
|
const client = getStatsClient();
|
|
Promise.allSettled([client.getVocabulary(500), client.getKanji(200), client.getKnownWords()])
|
|
.then(([wordsResult, kanjiResult, knownResult]) => {
|
|
if (cancelled) return;
|
|
const errors: string[] = [];
|
|
|
|
if (wordsResult.status === 'fulfilled') {
|
|
setWords(wordsResult.value);
|
|
} else {
|
|
errors.push(wordsResult.reason.message);
|
|
}
|
|
|
|
if (kanjiResult.status === 'fulfilled') {
|
|
setKanji(kanjiResult.value);
|
|
} else {
|
|
errors.push(kanjiResult.reason.message);
|
|
}
|
|
|
|
if (knownResult.status === 'fulfilled') {
|
|
setKnownWords(new Set(knownResult.value));
|
|
}
|
|
|
|
if (errors.length > 0) {
|
|
setError(errors.join('; '));
|
|
}
|
|
})
|
|
.finally(() => {
|
|
if (cancelled) return;
|
|
setLoading(false);
|
|
});
|
|
return () => {
|
|
cancelled = true;
|
|
};
|
|
}, [reloadToken]);
|
|
|
|
return { words, kanji, knownWords, loading, error, reload };
|
|
}
|