From 4d30339c34782a6e3d313804fa393c95ad38c4b2 Mon Sep 17 00:00:00 2001
From: TrainDoctor <traindoctor@protonmail.com>
Date: Sat, 29 Oct 2022 15:03:12 -0700
Subject: Add StoreSelect component

---
 .../settings/pages/general/StoreSelect.tsx         | 52 ++++++++++++++++++++++
 1 file changed, 52 insertions(+)
 create mode 100644 frontend/src/components/settings/pages/general/StoreSelect.tsx

(limited to 'frontend/src/components/settings/pages/general/StoreSelect.tsx')

diff --git a/frontend/src/components/settings/pages/general/StoreSelect.tsx b/frontend/src/components/settings/pages/general/StoreSelect.tsx
new file mode 100644
index 00000000..c24bacb9
--- /dev/null
+++ b/frontend/src/components/settings/pages/general/StoreSelect.tsx
@@ -0,0 +1,52 @@
+import { Dropdown, Field, TextField } from 'decky-frontend-lib';
+import { FunctionComponent } from 'react';
+import { FaShapes } from 'react-icons/fa';
+
+import Logger from '../../../../logger';
+import { Store } from '../../../../store';
+import { useSetting } from '../../../../utils/hooks/useSetting';
+
+const logger = new Logger('StoreSelect');
+
+const StoreSelect: FunctionComponent<{}> = () => {
+  const [selectedStore, setSelectedStore] = useSetting<Store>('store', Store.Default);
+  const [selectedStoreURL, setSelectedStoreURL] = useSetting<string | null>('store-url', null);
+
+  // Returns numerical values from 0 to 2 (with current branch setup as of 8/28/22)
+  // 0 being Default, 1 being Testing and 2 being Custom
+  return (
+    <>
+      <Field label="Store Channel">
+        <Dropdown
+          rgOptions={Object.values(Store)
+            .filter((store) => typeof store == 'string')
+            .map((store) => ({
+              label: store,
+              data: Store[store],
+            }))}
+          selectedOption={selectedStore}
+          onChange={async (newVal) => {
+            await setSelectedStore(newVal.data);
+            logger.log('switching stores!');
+          }}
+        />
+      </Field>
+      {selectedStore == Store.Custom && (
+        <Field
+          label="Custom Store"
+          indentLevel={1}
+          description={
+            <TextField
+              label={'URL'}
+              value={selectedStoreURL || undefined}
+              onChange={(e) => setSelectedStoreURL(e?.target.value || null)}
+            />
+          }
+          icon={<FaShapes style={{ display: 'block' }} />}
+        ></Field>
+      )}
+    </>
+  );
+};
+
+export default StoreSelect;
-- 
cgit v1.2.3

