Skip to content

Commit

Permalink
Added Currently selected star & fixed Patch
Browse files Browse the repository at this point in the history
  • Loading branch information
CEbbinghaus committed Nov 20, 2023
1 parent ea88921 commit f94d82a
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 86 deletions.
109 changes: 61 additions & 48 deletions src/components/LibraryModal.tsx
Original file line number Diff line number Diff line change
@@ -1,55 +1,68 @@
import React, { ReactElement, useEffect, useRef, useState} from 'react';
import React, { ReactElement, useEffect, useRef, useState } from 'react';
import { FaSdCard } from 'react-icons/fa';
import { Logger } from '../Logging';
import { API_URL, UNAMED_CARD_NAME } from '../const';
import { useCardsForGame } from "../../lib/src"

export default function LibraryModal({appId: gameId}: {appId: string}): ReactElement {
const {cards} = useCardsForGame({url: API_URL, logger: Logger, gameId});

var ref = useRef();

const height = 20;
const [top, setTop] = useState<number>(210);

useEffect(() => {
if(!ref || !ref.current) return;
const doc = (ref.current as unknown as HTMLElement).getRootNode() as Document;
// const playButton = document.querySelector("[class^='appactionbutton_PlayButton']");

const imageWindow = doc.querySelector("[class^='appdetails_Header']");
const imageWindowBounds = imageWindow?.getBoundingClientRect();

if(!imageWindowBounds)
return;

setTop(imageWindowBounds.height - height);
Logger.Log("Set Top For Window bacuse of bounds", {imageWindowBounds});
}, []);

if(!cards)
{
//Logger.Error("Unable to find Card");
return (<></>);
}

if(!cards.length)
{
Logger.Debug("No MicroSD card could be found for {appId}", {appId: gameId});
return (<></>);
}

return (
<div
//@ts-ignore
ref={ref}
className="microsdeck-app-modal"
style={{ position: 'absolute', height, top, left: '20px' }}
>
<FaSdCard size={20} />
<span>
const logger = Logger.Child({ module: "patching" });

export default function LibraryModal({ appId: gameId }: { appId: string }): ReactElement {
const { cards } = useCardsForGame({ url: API_URL, logger: Logger, gameId });

var ref = useRef();

const bottomMargin = 8;
const height = 20;
const [top, setTop] = useState<number>(210);

useEffect(() => {
logger.Debug("Processing Bounds");
if (!ref || !ref.current) {
logger.Debug("Couldn't get reference to HTML element");
return;
}
const element = (ref.current as unknown as HTMLElement);
const doc = element.getRootNode() as Document;

// const playButton = document.querySelector("[class^='appactionbutton_PlayButton']");

const imageWindow = doc.querySelector("[class^='appdetails_Header']");
const imageWindowBounds = imageWindow?.getBoundingClientRect();
const elementBounds = element.getBoundingClientRect()

if (!imageWindowBounds || !elementBounds)
return;


const topOffset = imageWindowBounds.height - elementBounds.height - bottomMargin;
setTop(topOffset);
logger.Debug("Set Top to {topOffset}. Banner Height: {bannerHeight}, Element Height: {elementHeight}, Desired Bottom Margin: {bottomMargin}", {topOffset, bannerHeight: imageWindowBounds.height, elementHeight: elementBounds.height, bottomMargin})
logger.Log("Set Top For Window bacuse of bounds", { imageWindowBounds });
}, [cards]);

if (!cards) {
logger.Debug("Unable to find Card");
return (<></>);
}

if (!cards.length) {
logger.Debug("No MicroSD card could be found for {appId}", { appId: gameId });
return (<></>);
}

return (
<div
//@ts-ignore
ref={ref}
className="microsdeck-app-modal"
style={{ padding: "0.4em", borderRadius: "6px", backgroundColor: "#0c131b", position: 'absolute', height, top, left: '20px' }}
>
<div style={{ float: "left" }}>
<FaSdCard size={18} />
</div>
<div style={{ marginLeft: "1.4rem", lineHeight: "18px", fontSize: 18, fontWeight: "bold" }} className="tab-label">
{cards.map(v => v.name || UNAMED_CARD_NAME).join(", ")}
</span>
</div>
)
</div>
</div>
)
}
43 changes: 5 additions & 38 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
showContextMenu,
staticClasses,
} from "decky-frontend-lib";
import { FaEllipsisH, FaSdCard } from "react-icons/fa";
import { FaEllipsisH, FaSdCard, FaStar } from "react-icons/fa";
import PatchAppScreen from "./patch/PatchAppScreen";
import { API_URL, DOCUMENTATION_PATH, UNAMED_CARD_NAME } from "./const";
import { Logger } from "./Logging";
Expand Down Expand Up @@ -72,26 +72,16 @@ function Content() {

const isLoaded = !!cardsAndGames;

// const [selectedCard, setSelectedCard] = useState<number>(0);

// Logger.Log("Currently Selected Card: {selectedCard}", { selectedCard });

// const dropdownOptions = cards?.map(([card], index) => {
// return {
// label: <div>{card.name ?? `Unamed - ${card.uid}`}</div>,
// data: index,
// } as DropdownOption
// }) ?? [{ label: "Loading...", data: null } as DropdownOption];


const entries = cardsAndGames?.sort(([a], [b]) => a.position - b.position).map(([card], index) => {
const currentCardMark = card.uid === currentCard?.uid ? (<small style={{marginLeft: "0.5em"}}><FaStar size={12} /></small>) : "";

return {
label:
<div style={{ width: "100%" }} className="tab-label-cont">
<div style={{ float: "left" }}>
<FaSdCard size={14} />
</div>
<div style={{ marginLeft: "1.2rem", fontSize: 18, fontWeight: "bold" }} className="tab-label">{card.name || UNAMED_CARD_NAME}</div>
<div style={{ marginLeft: "1.2rem", fontSize: 18, fontWeight: "bold" }} className="tab-label">{card.name || UNAMED_CARD_NAME}{currentCardMark}</div>
<div style={{ position: "absolute", bottom: 0, left: 0, fontSize: 8, color: "#aaa", whiteSpace: "nowrap" }}>{card.uid}</div>
</div>
,
Expand All @@ -113,16 +103,6 @@ function Content() {
<div style={{ margin: "5px", marginTop: "0px" }}>
Rename, Reorder or Remove MicroSD Cards
</div>
{/* <PanelSection>
<PanelSectionRow>
<DialogButton
onClick={() => {
Router.Navigate(CONFIGURATION_PATH);
Router.CloseSideMenus();
}}
>Open Settings Page</DialogButton>
</PanelSectionRow>
</PanelSection> */}
<PanelSection title="Cards">
{isLoaded ? (
<ReorderableList<MicroSDCard>
Expand All @@ -144,19 +124,6 @@ function Content() {
Loading...
</div>
)}
{/*
<PanelSectionRow>
<Dropdown
focusable={true}
disabled={!cards || !cards.length}
rgOptions={dropdownOptions}
selectedOption={selectedCard}
onChange={handleDropDownChange}
/>
</PanelSectionRow>
<PanelSectionRow>
{cards && <RenderCard data={cards[selectedCard]} />}
</PanelSectionRow> */}
</PanelSection>
</Focusable>
</>
Expand Down Expand Up @@ -184,7 +151,7 @@ export default definePlugin((serverApi: ServerAPI) => {
Logger.Log("Started MicroSDeck");

return {
title: <div className={staticClasses.Title}>Example Plugin</div>,
title: <div className={staticClasses.Title}>MicroSDeck</div>,
content:
<MicroSDeckContextProvider microSDeck={window.MicroSDeck}>
<Content />
Expand Down

0 comments on commit f94d82a

Please sign in to comment.