generated from SteamDeckHomebrew/Plugin-Template
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix require cycles and extract themecard
- Loading branch information
Showing
12 changed files
with
88 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,68 @@ | ||
import { PartialCSSThemeInfo } from "@/types"; | ||
import { ColumnNumbers, useThemeBrowserSharedValue, useThemeBrowserStoreValue } from "../context"; | ||
import { forwardRef } from "react"; | ||
import { shortenNumber, useThemeInstallState } from "@/lib"; | ||
import { useCSSLoaderValue } from "@/backend"; | ||
import { AiOutlineDownload } from "react-icons/ai"; | ||
import { Focusable } from "@decky/ui"; | ||
import { FaBullseye, FaDownload, FaStar } from "react-icons/fa6"; | ||
import { useExpandedViewAction } from "@/modules/expanded-view"; | ||
import { useThemeInstallState } from "../../hooks"; | ||
// Hard-coded path to prevent require cycle | ||
import { shortenNumber } from "../../utils/shorten-number"; | ||
|
||
interface ThemeCardProps { | ||
theme: PartialCSSThemeInfo; | ||
size?: ColumnNumbers; | ||
onClick?: () => void; | ||
} | ||
|
||
const cardWidth = { | ||
5: 152, | ||
4: 195, | ||
3: 260, | ||
}; | ||
export const ThemeCard = forwardRef<HTMLDivElement, ThemeCardProps>(({ theme, onClick }, ref) => { | ||
const apiUrl = useCSSLoaderValue("apiUrl"); | ||
const installStatus = useThemeInstallState(theme); | ||
|
||
export const ThemeCard = forwardRef<HTMLDivElement, ThemeCardProps>( | ||
({ theme, size, onClick }, ref) => { | ||
const apiUrl = useCSSLoaderValue("apiUrl"); | ||
const browserCardSize = useThemeBrowserSharedValue("browserCardSize"); | ||
const cols = size ?? browserCardSize; | ||
const installStatus = useThemeInstallState(theme); | ||
const imageUrl = | ||
theme?.images[0]?.id && theme.images[0].id !== "MISSING" | ||
? `${apiUrl}/blobs/${theme.images[0].id}` | ||
: `https://share.deckthemes.com/cssplaceholder.png`; | ||
|
||
const openTheme = useExpandedViewAction("openTheme"); | ||
|
||
const imageUrl = | ||
theme?.images[0]?.id && theme.images[0].id !== "MISSING" | ||
? `${apiUrl}/blobs/${theme.images[0].id}` | ||
: `https://share.deckthemes.com/cssplaceholder.png`; | ||
|
||
return ( | ||
<div className="relative"> | ||
{installStatus === "outdated" && ( | ||
<div className="cl_storeitem_notifbubble"> | ||
<AiOutlineDownload className="cl_storeitem_bubbleicon" /> | ||
</div> | ||
)} | ||
<Focusable | ||
ref={ref} | ||
className="cl_storeitem_container" | ||
focusWithinClassName="gpfocuswithin" | ||
onActivate={() => { | ||
onClick?.(); | ||
openTheme(theme.id); | ||
}} | ||
> | ||
<div className="cl_storeitem_imagecontainer"> | ||
<img | ||
className="cl_storeitem_image" | ||
src={imageUrl} | ||
width={cardWidth[cols]} | ||
height={(cardWidth[cols] / 16) * 10} | ||
/> | ||
<div className="cl_storeitem_imagedarkener" /> | ||
<div className="cl_storeitem_supinfocontainer"> | ||
<div className="cl_storeitem_iconinfoitem"> | ||
<FaDownload /> | ||
<span> | ||
{shortenNumber(theme.download.downloadCount) ?? theme.download.downloadCount} | ||
</span> | ||
</div> | ||
<div className="cl_storeitem_iconinfoitem"> | ||
<FaStar /> | ||
<span>{shortenNumber(theme.starCount) ?? theme.starCount}</span> | ||
</div> | ||
<div className="cl_storeitem_iconinfoitem"> | ||
<FaBullseye /> | ||
<span>{theme.target}</span> | ||
</div> | ||
return ( | ||
<div className="relative"> | ||
{installStatus === "outdated" && ( | ||
<div className="cl_storeitem_notifbubble"> | ||
<AiOutlineDownload className="cl_storeitem_bubbleicon" /> | ||
</div> | ||
)} | ||
<Focusable | ||
ref={ref} | ||
className="cl_storeitem_container" | ||
focusWithinClassName="gpfocuswithin" | ||
onActivate={onClick} | ||
> | ||
<div className="cl_storeitem_imagecontainer"> | ||
<img className="cl_storeitem_image" src={imageUrl} /> | ||
<div className="cl_storeitem_imagedarkener" /> | ||
<div className="cl_storeitem_supinfocontainer"> | ||
<div className="cl_storeitem_iconinfoitem"> | ||
<FaDownload /> | ||
<span> | ||
{shortenNumber(theme.download.downloadCount) ?? theme.download.downloadCount} | ||
</span> | ||
</div> | ||
<div className="cl_storeitem_iconinfoitem"> | ||
<FaStar /> | ||
<span>{shortenNumber(theme.starCount) ?? theme.starCount}</span> | ||
</div> | ||
<div className="cl_storeitem_iconinfoitem"> | ||
<FaBullseye /> | ||
<span>{theme.target}</span> | ||
</div> | ||
</div> | ||
<div className="cl_storeitem_maininfocontainer"> | ||
<span className="cl_storeitem_title">{theme.displayName}</span> | ||
<span className="cl_storeitem_subtitle"> | ||
{theme.version} - Last Updated {new Date(theme.updated).toLocaleDateString()} | ||
</span> | ||
<span className="cl_storeitem_subtitle">By {theme.specifiedAuthor}</span> | ||
</div> | ||
</Focusable> | ||
</div> | ||
); | ||
} | ||
); | ||
</div> | ||
<div className="cl_storeitem_maininfocontainer"> | ||
<span className="cl_storeitem_title">{theme.displayName}</span> | ||
<span className="cl_storeitem_subtitle"> | ||
{theme.version} - Last Updated {new Date(theme.updated).toLocaleDateString()} | ||
</span> | ||
<span className="cl_storeitem_subtitle">By {theme.specifiedAuthor}</span> | ||
</div> | ||
</Focusable> | ||
</div> | ||
); | ||
}); |
7 changes: 3 additions & 4 deletions
7
src/lib/components/theme-card/ThemeCardCSSVariableProvider.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
import { themeCardStylesGenerator } from "@/styles"; | ||
import { ColumnNumbers, useThemeBrowserSharedValue } from "../context"; | ||
|
||
export function ThemeCardCSSVariableProvider({ cardSize }: { cardSize?: ColumnNumbers }) { | ||
const browserCardSize = useThemeBrowserSharedValue("browserCardSize"); | ||
export type ColumnNumbers = 3 | 4 | 5; | ||
|
||
return <style>{themeCardStylesGenerator(cardSize || browserCardSize)}</style>; | ||
export function ThemeCardCSSVariableProvider({ cardSize }: { cardSize: ColumnNumbers }) { | ||
return <style>{themeCardStylesGenerator(cardSize)}</style>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./ThemeCard"; | ||
export * from "./ThemeCardCSSVariableProvider"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
src/modules/theme-store/components/ThemeCardCSSVariableProvider.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
export * from "./ThemeCardCSSVariableProvider"; | ||
export * from "./ThemeBrowserPage"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters