()
| 12 | import { UpdateIcon } from "./icons/update"; |
| 13 | |
| 14 | export const Packages = () => { |
| 15 | const ref = React.useRef<FireworksHandlers>(null); |
| 16 | const [packages, setPackages] = React.useState<PackageType[]>([]); |
| 17 | const [visible, setVisible] = React.useState(false); |
| 18 | const [outdatedPackages, setOutdatedPackages] = React.useState<string[]>([]); |
| 19 | |
| 20 | React.useEffect(() => { |
| 21 | getInstalledPackages().then((data) => { |
| 22 | setPackages(data); |
| 23 | }); |
| 24 | }, []); |
| 25 | |
| 26 | const fireworks = React.useCallback(() => { |
| 27 | if (ref.current) { |
| 28 | ref.current.start(); |
| 29 | setTimeout(() => { |
| 30 | ref.current?.waitStop(); |
| 31 | }, 3000); |
| 32 | } |
| 33 | }, []); |
| 34 | |
| 35 | const [installingAll, setInstallingAll] = React.useState(false); |
| 36 | const [installInProgress, setInstallInProgress] = React.useState(false); |
| 37 | |
| 38 | const onInstall = React.useCallback(async (packagesToInstall: string[]) => { |
| 39 | setInstallInProgress(true); |
| 40 | const state = await installPackages(packagesToInstall); |
| 41 | |
| 42 | if (state) { |
| 43 | fireworks(); |
| 44 | getInstalledPackages({ force: true }).then((data) => { |
| 45 | setPackages(data); |
| 46 | }); |
| 47 | setOutdatedPackages((p) => |
| 48 | p.filter((item) => !packagesToInstall.includes(item)), |
| 49 | ); |
| 50 | } |
| 51 | |
| 52 | setInstallInProgress(false); |
| 53 | |
| 54 | return state; |
| 55 | }, []); |
| 56 | |
| 57 | const onOutdated = React.useCallback((packages: string[]) => { |
| 58 | setOutdatedPackages((p) => [...p, ...packages]); |
| 59 | }, []); |
| 60 | |
| 61 | const onUpdateAll = React.useCallback(async () => { |
| 62 | if (installingAll) { |
| 63 | return; |
| 64 | } |
| 65 | setInstallingAll(true); |
| 66 | await onInstall(outdatedPackages); |
| 67 | setInstallingAll(false); |
| 68 | }, [outdatedPackages, installingAll, onInstall]); |
| 69 | |
| 70 | return ( |
| 71 | <> |
nothing calls this directly
no test coverage detected