[feature-274] Add setting to select the default platfrom to download BS

This commit is contained in:
MathieuG-P
2023-10-29 13:04:22 +01:00
parent 78d55bd6ae
commit 685313a133
7 changed files with 99 additions and 47 deletions
@@ -6,11 +6,14 @@ import { BsStore } from "shared/models/bs-store.enum";
import { useState } from "react";
import tailwindConfig from "../../../../../../tailwind.config";
import Color from "color";
import { useNavigate } from "react-router-dom";
export const ChooseStore: ModalComponent<BsStore> = ({ resolver }) => {
const t = useTranslation();
const navigate = useNavigate();
const [oculusHover, setOculusHover] = useState(false);
const [steamHover, setSteamHover] = useState(false);
@@ -18,6 +21,11 @@ export const ChooseStore: ModalComponent<BsStore> = ({ resolver }) => {
resolver({ exitCode: ModalExitCode.COMPLETED, data: store });
}
const goToSettings = () => {
resolver({ exitCode: ModalExitCode.CANCELED });
navigate("/settings#choose-default-store");
}
const isDarkMode = document.documentElement.classList.contains("dark");
const bg = (() => {
@@ -37,10 +45,10 @@ export const ChooseStore: ModalComponent<BsStore> = ({ resolver }) => {
// TODO : Translate
return (
<form className="flex flex-col gap-3">
<form className="flex flex-col gap-3 max-w-sm">
<h1 className="text-3xl uppercase tracking-wide w-full text-center text-gray-800 dark:text-gray-200">{t("which platform ?")}</h1>
<p className="max-w-sm text-gray-800 dark:text-gray-200 text-center">Select the platfrom where you own Beat Saber or from which you want to download it.</p>
<div className="flex flex-row w-full flex-grow gap-4">
<p className="w-auto text-gray-800 dark:text-gray-200 text-center">Select the platfrom where you own Beat Saber or from which you want to download it.</p>
<div className="flex flex-row w-full flex-grow gap-3">
<div className="flex flex-col flex-grow basis-0 gap-2 text-center px-5 pt-3 pb-1 rounded-md border-main-color-3 border-2 cursor-pointer" onMouseEnter={() => setOculusHover(true)} onMouseLeave={() => setOculusHover(false)} onClick={() => chooseStore(BsStore.OCULUS)} style={{backgroundColor: oculusHover ? bg.dim : bg.bright}}>
<OculusIcon className="flex-grow aspect-square text-black bg-white rounded-full p-5"/>
<h2 className="font-bold">Oculus Store (PC)</h2>
@@ -50,6 +58,7 @@ export const ChooseStore: ModalComponent<BsStore> = ({ resolver }) => {
<h2 className="font-bold">Steam</h2>
</div>
</div>
<p onClick={goToSettings} className="text-sm italic underline cursor-pointer">Définir la platforme par défaut dans les paramètres</p>
</form>
);
};
@@ -1,24 +1,37 @@
import { motion } from "framer-motion";
import { useTranslation } from "renderer/hooks/use-translation.hook";
import { BsmIcon, BsmIconType } from "../svgs/bsm-icon.component";
import { CSSProperties } from "react"
export function SettingRadioArray({ items, selectedItem = items[0].id, onItemSelected }: { items: RadioItem[]; selectedItem?: number; onItemSelected?: (id: number) => void }) {
type Props<T> = {
id?: HTMLDivElement["id"];
items: RadioItem<T>[];
selectedItemId?: number;
selectedItemValue?: T;
direction?: CSSProperties["flexDirection"],
onItemSelected?: (item: RadioItem<T>) => void
};
export function SettingRadioArray<T>({ id, items, selectedItemId, selectedItemValue, onItemSelected, direction = "column" }: Props<T>) {
const t = useTranslation();
const isSelected = (item: RadioItem<T>) => {
return item.id === selectedItemId || item.value === selectedItemValue;
}
return (
<div className="w-full">
<div id={id} className="w-full flex gap-1.5" style={{flexDirection: direction}}>
{items.map(i => (
<div onClick={() => onItemSelected(i.id)} key={i.id} className={`py-3 my-[6px] w-full flex cursor-pointer justify-between items-center rounded-md px-2 transition-colors duration-200 ${i.id === selectedItem ? "bg-light-main-color-3 dark:bg-main-color-3" : "bg-light-main-color-1 dark:bg-main-color-1"}`}>
<div onClick={() => onItemSelected(i)} key={i.id} className={`py-3 w-full flex cursor-pointer justify-between items-center rounded-md px-2 transition-colors duration-200 ${isSelected(i) ? "bg-light-main-color-3 dark:bg-main-color-3" : "bg-light-main-color-1 dark:bg-main-color-1"} ${i.className}`}>
<div className="flex items-center">
<div className="h-5 rounded-full aspect-square border-2 border-gray-800 dark:border-white p-[3px] mr-2">
<motion.span initial={{ scale: 0 }} animate={{ scale: i.id === selectedItem ? 1 : 0 }} className="h-full w-full block bg-gray-800 dark:bg-white rounded-full" />
<motion.span initial={{ scale: 0 }} animate={{ scale: isSelected(i) ? 1 : 0 }} className="h-full w-full block bg-gray-800 dark:bg-white rounded-full" />
</div>
<h2 className="font-extrabold">{t(i.text)}</h2>
</div>
{i.icon && (
<div className="flex items-center">
{i.textIcon && <span className="text-sm">{t(i.textIcon)}</span>}
<BsmIcon icon={i.icon} className="max-h-5 w-fit ml-2" />
{i.icon}
</div>
)}
</div>
@@ -27,10 +40,11 @@ export function SettingRadioArray({ items, selectedItem = items[0].id, onItemSel
);
}
export interface RadioItem {
export interface RadioItem<T> {
id: number;
text: string;
icon?: BsmIconType;
icon?: JSX.Element;
textIcon?: string;
value?: any;
className?: string;
value?: T;
}
@@ -1,12 +1,12 @@
import { forwardRef, HTMLProps } from "react";
export const OculusIcon = forwardRef<SVGSVGElement, HTMLProps<SVGSVGElement>>((props, ref) => {
export function OculusIcon(props: HTMLProps<SVGSVGElement>) {
return (
<svg ref={ref} {...props} xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
<svg {...props} xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
<path
fill="currentColor"
d="M24.182 18.599c-0.427 0.297-0.901 0.474-1.411 0.552-0.51 0.083-1.016 0.068-1.521 0.068h-10.5c-0.51 0-1.016 0.021-1.526-0.068-0.51-0.083-0.979-0.255-1.411-0.552-0.854-0.604-1.365-1.563-1.365-2.604 0-1.057 0.516-2.016 1.37-2.599 0.417-0.297 0.896-0.479 1.396-0.557 0.5-0.083 1-0.083 1.526-0.083h10.5c0.5 0 1.016-0.016 1.516 0.063s0.984 0.26 1.401 0.542c0.865 0.578 1.365 1.557 1.365 2.599 0 1.036-0.526 2-1.38 2.599zM28.411 8.526c-1.125-0.906-2.417-1.531-3.818-1.865-0.802-0.193-1.604-0.281-2.432-0.307-0.599-0.021-1.198-0.010-1.818-0.010h-8.661c-0.609 0-1.224-0.010-1.833 0.010-0.823 0.026-1.63 0.109-2.432 0.307-1.401 0.339-2.698 0.964-3.818 1.865-2.281 1.823-3.599 4.568-3.599 7.474 0 2.911 1.318 5.656 3.583 7.474 1.13 0.906 2.422 1.531 3.823 1.87 0.802 0.193 1.609 0.281 2.432 0.302 0.599 0.021 1.198 0.016 1.818 0.016h8.661c0.599 0 1.219 0.005 1.818-0.016 0.823-0.021 1.62-0.109 2.417-0.302 1.401-0.344 2.682-0.969 3.823-1.87 2.307-1.823 3.625-4.568 3.625-7.474s-1.318-5.656-3.589-7.474z"
/>
</svg>
);
})
}