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
8 changed files
with
492 additions
and
84 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
102 changes: 102 additions & 0 deletions
102
src/modules/expanded-view/components/ExpandedViewButtonsSection.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,102 @@ | ||
import { shortenNumber, useThemeInstallState } from "@/lib"; | ||
import { useExpandedViewAction, useExpandedViewValue } from "../context"; | ||
import { FaRegStar, FaStar } from "react-icons/fa"; | ||
import { DialogButton } from "@decky/ui"; | ||
import { useState } from "react"; | ||
import { useCSSLoaderAction, useCSSLoaderValue } from "@/backend"; | ||
import { ImCog } from "react-icons/im"; | ||
|
||
export function ExpandedViewButtonsSection() { | ||
const data = useExpandedViewValue("data"); | ||
const isStarred = useExpandedViewValue("isStarred"); | ||
const toggleStar = useExpandedViewAction("toggleStar"); | ||
|
||
const apiFullToken = useCSSLoaderValue("apiFullToken"); | ||
const [starButtonBlurred, setStarButtonBlurred] = useState<boolean>(false); | ||
|
||
const isWorking = useCSSLoaderValue("isWorking"); | ||
|
||
const installTheme = useCSSLoaderAction("installTheme"); | ||
|
||
const installStatus = useThemeInstallState(data); | ||
|
||
async function handleStar() { | ||
setStarButtonBlurred(true); | ||
await toggleStar(); | ||
setStarButtonBlurred(false); | ||
} | ||
|
||
return ( | ||
<div className="cl_expandedview_buttonscontainer"> | ||
{/* Star */} | ||
<div className="cl_expandedview_singlebuttoncontainer"> | ||
<div className="w-full justify-between"> | ||
<div className="flex gap-1 items-center"> | ||
{isStarred ? <FaStar /> : <FaRegStar />} | ||
{/* Need to make the text size smaller or else it wraps */} | ||
<span style={{ fontSize: data.starCount >= 100 ? "0.75rem" : "1rem" }}> | ||
{shortenNumber(data.starCount) ?? data.starCount} Star | ||
{data.starCount === 1 ? "" : "s"} | ||
</span> | ||
</div> | ||
<DialogButton | ||
className="cl_expandedview_starbutton" | ||
onClick={() => void handleStar()} | ||
disabled={starButtonBlurred || !apiFullToken} | ||
> | ||
<div className="flex items-center justify-center gap-1/4"> | ||
<span> | ||
{!apiFullToken ? "Log In to Star" : isStarred ? "Unstar Theme" : "Star Theme"} | ||
</span> | ||
</div> | ||
</DialogButton> | ||
</div> | ||
</div> | ||
|
||
{/* Download / Configure */} | ||
<div className="cl_expandedview_singlebuttoncontainer"> | ||
<div className="flex flex-col gap-1"> | ||
<span className="cl_expandedview_installtext">Install {data.displayName}</span> | ||
<span className="font-bold"> | ||
{shortenNumber(data.download.downloadCount) ?? data.download.downloadCount} Download | ||
{data.download.downloadCount === 1 ? "" : "s"} | ||
</span> | ||
<DialogButton | ||
// @ts-ignore | ||
ref={downloadButtonRef} | ||
className="cl_expandedview_bluebutton" | ||
disabled={isWorking} | ||
onClick={() => { | ||
installTheme(data.id); | ||
}} | ||
> | ||
<span className="CssLoader_ThemeBrowser_ExpandedView_InstallText"> | ||
{installStatus === "installed" && "Reinstall"} | ||
{installStatus === "outdated" && "Update"} | ||
{installStatus === "notinstalled" && "Install"} | ||
</span> | ||
</DialogButton> | ||
{installStatus === "installed" && ( | ||
<DialogButton | ||
onClick={() => { | ||
// TODO: THEME SETTINGS MODAL | ||
// showModal( | ||
// <ThemeSettingsModalRoot | ||
// selectedTheme={ | ||
// installedThemes.find((e) => e.id === fullThemeData.id)?.id || | ||
// // using name here because in submissions id is different | ||
// installedThemes.find((e) => e.name === fullThemeData.name)!.id | ||
// } | ||
// /> | ||
// ); | ||
}} | ||
className="relative" | ||
> | ||
<ImCog className="absolute-center" /> | ||
</DialogButton> | ||
)} | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |
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,3 +1,4 @@ | ||
export * from "./ExpandedViewLoadingPage"; | ||
export * from "./ExpandedViewScrollingSection"; | ||
export * from "./ExpandedViewCssVariables"; | ||
export * from "./ExpandedViewButtonsSection"; |
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
Oops, something went wrong.