MCPcopy Create free account
hub / github.com/Sethispr/image-compressor / App

Function App

App.tsx:20–359  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

18const SETTINGS_STORAGE_KEY = 'blairpng_settings_v1';
19
20const App = () => {
21 // settings
22 const [settings, setSettings] = useState<OptimizerConfiguration>(() => {
23 try {
24 const saved = localStorage.getItem(SETTINGS_STORAGE_KEY);
25 return saved
26 ? {...DEFAULT_SETTINGS, ...JSON.parse(saved)}
27 : DEFAULT_SETTINGS;
28 } catch {
29 return DEFAULT_SETTINGS;
30 }
31 });
32
33 useEffect(() => {
34 try {
35 localStorage.setItem(SETTINGS_STORAGE_KEY, JSON.stringify(settings));
36 } catch (err) {
37 console.error('Failed to save settings', err);
38 }
39 }, [settings]);
40
41 // theme ui
42 useEffect(() => {
43 const root = window.document.documentElement;
44 const applyTheme = (t: 'light' | 'dark') => {
45 if (t === 'dark') root.classList.add('dark');
46 else root.classList.remove('dark');
47 };
48
49 if (settings.theme === 'system') {
50 const systemTheme = window.matchMedia('(prefers-color-scheme: dark)')
51 .matches
52 ? 'dark'
53 : 'light';
54 applyTheme(systemTheme);
55 const media = window.matchMedia('(prefers-color-scheme: dark)');
56 const listener = (e: MediaQueryListEvent) =>
57 applyTheme(e.matches ? 'dark' : 'light');
58 media.addEventListener('change', listener);
59 return () => media.removeEventListener('change', listener);
60 } else {
61 applyTheme(settings.theme);
62 }
63 }, [settings.theme]);
64
65 // --- 3. STATE & HOOKS ---
66 const [inspectedJob, setInspectedJob] = useState<ImageJob | null>(null);
67 const [toast, setToast] = useState<{
68 message: string;
69 isVisible: boolean;
70 type: 'success' | 'error';
71 }>({message: '', isVisible: false, type: 'success'});
72
73 const {jobs, addFiles, removeJob, clearCompleted, clearAll, isProcessing} =
74 useOptimizer(settings);
75 const {isZipping, handleDownloadZip, handleDownloadIndividual} =
76 useDownloader();
77

Callers

nothing calls this directly

Calls 6

useOptimizerFunction · 0.90
useDownloaderFunction · 0.90
generateFilenameFunction · 0.90
downloadJobFunction · 0.90
applyThemeFunction · 0.85
showToastFunction · 0.85

Tested by

no test coverage detected