From de865192829c055607d2024a7523aed1ead21398 Mon Sep 17 00:00:00 2001 From: MathieuG-P <40181755+Zagrios@users.noreply.github.com> Date: Thu, 10 Nov 2022 00:52:59 +0100 Subject: [PATCH] add map data --- .../local-maps-list-panel.component.tsx | 5 +- .../map-item.component.tsx | 105 +++++++++--------- 2 files changed, 53 insertions(+), 57 deletions(-) diff --git a/src/renderer/components/maps-mangement-components/local-maps-list-panel.component.tsx b/src/renderer/components/maps-mangement-components/local-maps-list-panel.component.tsx index 4edc4947..93cffab7 100644 --- a/src/renderer/components/maps-mangement-components/local-maps-list-panel.component.tsx +++ b/src/renderer/components/maps-mangement-components/local-maps-list-panel.component.tsx @@ -53,8 +53,9 @@ export function LocalMapsListPanel({version, className} : Props) { autor={map.rawInfo._levelAuthorName} songAutor={map.rawInfo._songAuthorName} bpm={map.rawInfo._beatsPerMinute} - duration={null} - diffs={extractMapDiffs(map)} mapId={map.bsaverInfo?.id} qualified={null} ranked={null} autorLink={null} + duration={null} + diffs={extractMapDiffs(map)} mapId={map.bsaverInfo?.id} qualified={null} ranked={null} autorId={map.bsaverInfo?.uploader?.id} plays={map.bsaverInfo?.stats?.plays} likes={map.bsaverInfo?.stats?.upvotes} createdAt={map.bsaverInfo?.createdAt} + onDelete={() => {}} />; } diff --git a/src/renderer/components/maps-mangement-components/map-item.component.tsx b/src/renderer/components/maps-mangement-components/map-item.component.tsx index 8f0a1fd1..a627b627 100644 --- a/src/renderer/components/maps-mangement-components/map-item.component.tsx +++ b/src/renderer/components/maps-mangement-components/map-item.component.tsx @@ -4,7 +4,10 @@ import { useThemeColor } from "renderer/hooks/use-theme-color.hook"; import { BsmLink } from "../shared/bsm-link.component"; import { BsmIcon } from "../svgs/bsm-icon.component"; import { BsmButton } from "../shared/bsm-button.component"; -import { motion } from "framer-motion"; +import { animate, motion } from "framer-motion"; +import { useState } from "react"; +import { LinkOpenerService } from "renderer/services/link-opener.service"; +import dateFormat from "dateformat"; export type MapItemProps = { hash: string, @@ -13,82 +16,74 @@ export type MapItemProps = { songAutor: string, coverUrl: string, songUrl: string, - autorLink: string, + autorId: number, mapId: string, diffs: Map, qualified: boolean, ranked: boolean, bpm: number, duration: number, + likes: number, + plays: number, + createdAt: string, onDelete?: (hash: string) => void, onDownload?: (id: string) => void, } -export function MapItem({hash, title, autor, songAutor, coverUrl, songUrl, autorLink, mapId, diffs, qualified, ranked, onDelete, onDownload}: MapItemProps) { +export function MapItem({hash, title, autor, songAutor, coverUrl, songUrl, autorId, mapId, diffs, qualified, ranked, bpm, duration, likes, plays, createdAt, onDelete, onDownload}: MapItemProps) { + + const linkOpener = LinkOpenerService.getInstance(); const color = useThemeColor("first-color"); + const [hovered, setHovered] = useState(false); + const zipUrl = `https://r2cdn.beatsaver.com/${hash}.zip`; const previewUrl = `https://skystudioapps.com/bs-viewer/?url=${zipUrl}`; const mapUrl = mapId ? `https://beatsaver.com/maps/${mapId}` : null; + const authorUrl = autorId ? `https://beatsaver.com/profile/${autorId}` : null; + const createdDate = createdAt ? dateFormat(createdAt, "d mmm yyyy") : null; - - const renderAutor = () => { - if(!autor){ null; } - if(autorLink){ - return {autor} + const openMapPage = () => { + if(mapUrl){ + linkOpener.open(mapUrl) } - return {autor} - } - - const renderDiff = (charac: BsvMapCharacteristic, diff: BsvMapDifficultyType) => { - - const colorPill = diffColors[diff] ?? ""; - - return ( -
  • - - {diff === "ExpertPlus" ? "Expert+" : diff} -
  • - ) - } - - const scrollDiffs = (e: React.MouseEvent) => { - - const el = e.currentTarget; - const rect = e.currentTarget.getBoundingClientRect(); - - console.log(el.scrollHeight - (el.scrollWidth - el.clientWidth)) - - let yProgress = (((e.clientX - rect.left) - ((el.clientWidth / el.scrollWidth) * 100)) / (rect.width)); - - yProgress = yProgress < 0 ? 0 : yProgress > 1 ? 1 : yProgress; - - e.currentTarget.scrollTo({left: e.currentTarget.scrollWidth * yProgress}) - } - - const resetScrollDiffs = (e: React.MouseEvent) => { - e.currentTarget.scrollTo({left: 0, behavior: "smooth"}); } + const openPreview = () => linkOpener.open(previewUrl, true); + const copyBsr = () => navigator.clipboard.writeText(`!bsr ${mapId}`); + const playSong = () => new Audio(songUrl).play(); + return ( -
  • -
    - - + setHovered(true)} onHoverEnd={() => setHovered(false)} onClick={openMapPage}> +
    +
    + + {e.stopPropagation(); playSong()}}> + + +
    +
    + +
    +

    {title}

    +

    par {songAutor}

    +

    mappée par {autor}

    +
    +
    + + + + +
    + {onDelete && {e.stopPropagation(); openPreview()}}/>} + {e.stopPropagation(); openPreview()}}/> + {mapId && {e.stopPropagation(); copyBsr()}}/>} +
    +
    -
    - -
    -

    {title}

    -

    par {songAutor}

    -

    mappée par {autor}

    -
    -
    -
    - sp -
    -
  • + + ) }