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.
- Loading branch information
Showing
34 changed files
with
503 additions
and
40 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,7 +1,5 @@ | ||
export * from "./title-view"; | ||
export * from "./motd-display"; | ||
export * from "./style-provider"; | ||
export * from "./preset-selection-dropdown"; | ||
export * from "./theme-patch"; | ||
export * from "./optional-deps-modal"; | ||
export * from "./nav-patch-info-modal"; | ||
export * from "./modals"; |
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 "./nav-patch-info-modal"; | ||
export * from "./optional-deps-modal"; |
2 changes: 1 addition & 1 deletion
2
...av-patch-info-modal/NavPatchInfoModal.tsx → ...av-patch-info-modal/NavPatchInfoModal.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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...optional-deps-modal/OptionalDepsModal.tsx → ...optional-deps-modal/OptionalDepsModal.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
File renamed without changes.
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 +1,2 @@ | ||
export * from "./useForcedRerender"; | ||
export * from "./useThemeInstallState"; |
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,12 @@ | ||
import { LocalThemeStatus, PartialCSSThemeInfo, Theme } from "@/types"; | ||
import { useCSSLoaderStateValue } from "@/backend"; | ||
|
||
export function useThemeInstallState(theme: Theme | PartialCSSThemeInfo): LocalThemeStatus { | ||
const updateStatuses = useCSSLoaderStateValue("updateStatuses"); | ||
|
||
const status = updateStatuses.find((status) => status[0] === theme.id); | ||
if (status) { | ||
return status[1]; | ||
} | ||
return "notinstalled"; | ||
} |
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,3 +1,4 @@ | ||
export * from "./components"; | ||
export * from "./hooks"; | ||
export * from "./utils"; | ||
export * from "./providers"; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./style-provider"; |
File renamed without changes.
File renamed without changes.
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,3 @@ | ||
export * from "./classname-merger"; | ||
export * from "./toggleThemeWithModals"; | ||
export * from "./shorten-number"; |
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,48 @@ | ||
// Code from the short-number package, could not be imported due | ||
// to TypeScript issues. | ||
// https://www.npmjs.com/package/short-number | ||
|
||
export function shortenNumber(num: number) { | ||
if (typeof num !== "number") { | ||
throw new TypeError("Expected a number"); | ||
} | ||
|
||
if (num > 1e19) { | ||
throw new RangeError("Input expected to be < 1e19"); | ||
} | ||
|
||
if (num < -1e19) { | ||
throw new RangeError("Input expected to be > 1e19"); | ||
} | ||
|
||
if (Math.abs(num) < 1000) { | ||
return num; | ||
} | ||
|
||
var shortNumber; | ||
var exponent; | ||
var size; | ||
var sign = num < 0 ? "-" : ""; | ||
var suffixes = { | ||
K: 6, | ||
M: 9, | ||
B: 12, | ||
T: 16, | ||
}; | ||
|
||
num = Math.abs(num); | ||
size = Math.floor(num).toString().length; | ||
|
||
exponent = size % 3 === 0 ? size - 3 : size - (size % 3); | ||
shortNumber = String(Math.round(10 * (num / Math.pow(10, exponent))) / 10); | ||
|
||
for (var suffix in suffixes) { | ||
// @ts-ignore | ||
if (exponent < suffixes[suffix]) { | ||
shortNumber += suffix; | ||
break; | ||
} | ||
} | ||
|
||
return sign + shortNumber; | ||
} |
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,11 +1,43 @@ | ||
import { Focusable } from "@decky/ui"; | ||
import { useThemeBrowserStoreAction, useThemeBrowserStoreValue } from "../context"; | ||
import { BrowserSearchFields } from "./BrowserSearchFields"; | ||
import { useCSSLoaderStateValue } from "@/backend"; | ||
import { ThemeCard } from "./ThemeCard"; | ||
import { useEffect, useRef } from "react"; | ||
|
||
export function ThemeBrowserPage() { | ||
const initializeStore = useThemeBrowserStoreAction("initializeStore"); | ||
const themes = useThemeBrowserStoreValue("themes"); | ||
const indexToSnapToOnLoad = useThemeBrowserStoreValue("indexToSnapToOnLoad"); | ||
const backendVersion = useCSSLoaderStateValue("backendVersion"); | ||
|
||
const endOfPageRef = useRef<HTMLDivElement>(null); | ||
const firstCardRef = useRef<HTMLDivElement>(null); | ||
|
||
useEffect(() => { | ||
void initializeStore(); | ||
}, []); | ||
|
||
return ( | ||
<> | ||
<BrowserSearchFields /> | ||
|
||
<Focusable className="flex flex-wrap justify-center gap-3"> | ||
{themes.items | ||
.filter((theme) => theme.manifestVersion <= backendVersion) | ||
.map((theme, index) => ( | ||
<ThemeCard | ||
ref={ | ||
index === indexToSnapToOnLoad | ||
? endOfPageRef | ||
: index === 0 | ||
? firstCardRef | ||
: undefined | ||
} | ||
key={theme.id} | ||
theme={theme} | ||
/> | ||
))} | ||
</Focusable> | ||
</> | ||
); | ||
} |
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,15 +1,86 @@ | ||
import { PartialCSSThemeInfo } from "@/types"; | ||
import { useThemeBrowserSharedStateValue } from "../context"; | ||
import { | ||
ColumnNumbers, | ||
useThemeBrowserSharedStateValue, | ||
useThemeBrowserStoreValue, | ||
} from "../context"; | ||
import { forwardRef } from "react"; | ||
import { shortenNumber, useThemeInstallState } from "@/lib"; | ||
import { useCSSLoaderStateValue } from "@/backend"; | ||
import { AiOutlineDownload } from "react-icons/ai"; | ||
import { Focusable } from "@decky/ui"; | ||
import { FaBullseye, FaDownload, FaStar } from "react-icons/fa6"; | ||
|
||
interface ThemeCardProps { | ||
theme: PartialCSSThemeInfo; | ||
size?: number; | ||
size?: ColumnNumbers; | ||
} | ||
|
||
export const ThemeCard = forwardRef<HTMLElement, ThemeCardProps>(({ theme, size }, ref) => { | ||
const cardWidth = { | ||
5: 152, | ||
4: 195, | ||
3: 260, | ||
}; | ||
|
||
export const ThemeCard = forwardRef<HTMLDivElement, ThemeCardProps>(({ theme, size }, ref) => { | ||
const apiUrl = useCSSLoaderStateValue("apiUrl"); | ||
const browserCardSize = useThemeBrowserSharedStateValue("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`; | ||
|
||
return null; | ||
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={() => { | ||
// ADD IN CLICK LOGIC | ||
}} | ||
> | ||
<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> | ||
</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> | ||
); | ||
}); |
8 changes: 8 additions & 0 deletions
8
src/modules/theme-store/components/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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { themeCardStylesGenerator } from "@/styles"; | ||
import { useThemeBrowserSharedStateValue } from "../context"; | ||
|
||
export function ThemeCardCSSVariableProvider() { | ||
const browserCardSize = useThemeBrowserSharedStateValue("browserCardSize"); | ||
|
||
return <style>{themeCardStylesGenerator(browserCardSize)}</style>; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
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
Oops, something went wrong.