import { motion } from "framer-motion"; import { useEffect, useRef } from "react"; import { BsmProgressBar } from "renderer/components/progress-bar/bsm-progress-bar.component"; import { BsmImage } from "renderer/components/shared/bsm-image.component"; import TitleBar from "renderer/components/title-bar/title-bar.component"; import { useObservable } from "renderer/hooks/use-observable.hook"; import { useTranslation } from "renderer/hooks/use-translation.hook"; import { NotificationService } from "renderer/services/notification.service"; import { PlaylistDownloaderService } from "renderer/services/playlist-downloader.service"; import { map, filter, take, lastValueFrom } from "rxjs"; import defaultImage from "../../../../assets/images/default-version-img.jpg"; import { useService } from "renderer/hooks/use-service.hook"; import { useConstant } from "renderer/hooks/use-constant.hook"; import { useOnUpdate } from "renderer/hooks/use-on-update.hook"; import { useWindowArgs } from "renderer/hooks/use-window-args.hook"; import { useWindowControls } from "renderer/hooks/use-window-controls.hook"; export default function OneClickDownloadPlaylist() { const t = useTranslation(); const playlistDownloader = useService(PlaylistDownloaderService); const notification = useService(NotificationService); const { close: closeWindow } = useWindowControls(); const mapsContainer = useRef(null); const { playlistUrl } = useWindowArgs("playlistUrl"); const download$ = useConstant(() => playlistDownloader.oneClickInstallPlaylist(playlistUrl)); const playlistInfos = useObservable(() => download$.pipe(filter(progress => !!progress.data?.playlist), map(progress => progress.data.playlist), take(1))); const downloadedMaps = useObservable(() => download$.pipe(filter(progress => !!progress.data?.downloadedMaps), map(progress => progress.data.downloadedMaps))); useEffect(() => { lastValueFrom(download$).then(() => { notification.notifySystem({ title: "OneClick", body: t("notifications.playlists.one-click-install.success") }); }).catch(() => { notification.notifySystem({ title: t("notifications.types.error"), body: t("notifications.playlists.one-click-install.error") }); }).finally(() => { closeWindow(); }); }, []); useOnUpdate(() => { setTimeout(() => { mapsContainer.current.scrollTo({ left: mapsContainer.current.scrollWidth, behavior: "smooth",}); }, 500); }, [downloadedMaps]); const playlistImage = () => { if(!playlistInfos?.image) return defaultImage; if (playlistInfos?.image.startsWith("data:image")) { return playlistInfos?.image; } return `data:image/png;base64,${playlistInfos?.image}`; } return (
{playlistInfos && }

{playlistInfos?.playlistTitle}

{downloadedMaps?.map(map => map?.coverUrl && )}
); }