{sections.find((s) => s.id === selectedSection)?.label}
diff --git a/frontend/libs/components/settings-modal/tsconfig.json b/frontend/libs/components/settings-modal/tsconfig.json
index a85c4f44ce..4f5c504705 100644
--- a/frontend/libs/components/settings-modal/tsconfig.json
+++ b/frontend/libs/components/settings-modal/tsconfig.json
@@ -5,21 +5,27 @@
{
"path": "../modal"
},
+ {
+ "path": "../label"
+ },
+ {
+ "path": "../switch"
+ },
{
"path": "../select"
},
{
"path": "../../tauri-api"
},
+ {
+ "path": "../../soundboard"
+ },
{
"path": "../input"
},
{
"path": "../button"
},
- {
- "path": "../../soundboard"
- },
{
"path": "./tsconfig.lib.json"
},
diff --git a/frontend/libs/components/settings-modal/tsconfig.lib.json b/frontend/libs/components/settings-modal/tsconfig.lib.json
index a0adb87070..62d1c85923 100644
--- a/frontend/libs/components/settings-modal/tsconfig.lib.json
+++ b/frontend/libs/components/settings-modal/tsconfig.lib.json
@@ -46,20 +46,26 @@
{
"path": "../modal/tsconfig.lib.json"
},
+ {
+ "path": "../label/tsconfig.lib.json"
+ },
+ {
+ "path": "../switch/tsconfig.lib.json"
+ },
{
"path": "../select/tsconfig.lib.json"
},
{
"path": "../../tauri-api/tsconfig.lib.json"
},
+ {
+ "path": "../../soundboard/tsconfig.lib.json"
+ },
{
"path": "../input/tsconfig.lib.json"
},
{
"path": "../button/tsconfig.lib.json"
- },
- {
- "path": "../../soundboard/tsconfig.lib.json"
}
]
}
diff --git a/frontend/libs/components/switch/.babelrc b/frontend/libs/components/switch/.babelrc
new file mode 100644
index 0000000000..1ea870ead4
--- /dev/null
+++ b/frontend/libs/components/switch/.babelrc
@@ -0,0 +1,12 @@
+{
+ "presets": [
+ [
+ "@nx/react/babel",
+ {
+ "runtime": "automatic",
+ "useBuiltIns": "usage"
+ }
+ ]
+ ],
+ "plugins": []
+}
diff --git a/frontend/libs/components/switch/README.md b/frontend/libs/components/switch/README.md
new file mode 100644
index 0000000000..8260eb0135
--- /dev/null
+++ b/frontend/libs/components/switch/README.md
@@ -0,0 +1,7 @@
+# @storyteller/ui-switch
+
+This library was generated with [Nx](https://nx.dev).
+
+## Running unit tests
+
+Run `nx test @storyteller/ui-switch` to execute the unit tests via [Vitest](https://vitest.dev/).
diff --git a/frontend/libs/components/switch/package.json b/frontend/libs/components/switch/package.json
new file mode 100644
index 0000000000..70e60b78ac
--- /dev/null
+++ b/frontend/libs/components/switch/package.json
@@ -0,0 +1,17 @@
+{
+ "name": "@storyteller/ui-switch",
+ "version": "0.0.1",
+ "type": "module",
+ "main": "./dist/index.js",
+ "module": "./dist/index.js",
+ "types": "./dist/index.d.ts",
+ "exports": {
+ "./package.json": "./package.json",
+ ".": {
+ "development": "./src/index.ts",
+ "types": "./dist/index.d.ts",
+ "import": "./dist/index.js",
+ "default": "./dist/index.js"
+ }
+ }
+}
diff --git a/frontend/libs/components/switch/src/index.ts b/frontend/libs/components/switch/src/index.ts
new file mode 100644
index 0000000000..3f2441cfda
--- /dev/null
+++ b/frontend/libs/components/switch/src/index.ts
@@ -0,0 +1,2 @@
+
+export * from './lib/switch';
diff --git a/frontend/libs/components/switch/src/lib/switch.module.css b/frontend/libs/components/switch/src/lib/switch.module.css
new file mode 100644
index 0000000000..d0246c74b9
--- /dev/null
+++ b/frontend/libs/components/switch/src/lib/switch.module.css
@@ -0,0 +1,7 @@
+/*
+ * Replace this with your own classes
+ *
+ * e.g.
+ * .container {
+ * }
+*/
\ No newline at end of file
diff --git a/frontend/libs/components/switch/src/lib/switch.spec.tsx b/frontend/libs/components/switch/src/lib/switch.spec.tsx
new file mode 100644
index 0000000000..364763baec
--- /dev/null
+++ b/frontend/libs/components/switch/src/lib/switch.spec.tsx
@@ -0,0 +1,12 @@
+import { render } from '@testing-library/react';
+
+import Switch from './switch';
+
+describe('Switch', () => {
+
+ it('should render successfully', () => {
+ const { baseElement } = render();
+ expect(baseElement).toBeTruthy();
+ });
+
+});
diff --git a/frontend/libs/components/switch/src/lib/switch.tsx b/frontend/libs/components/switch/src/lib/switch.tsx
new file mode 100644
index 0000000000..5561b4eeda
--- /dev/null
+++ b/frontend/libs/components/switch/src/lib/switch.tsx
@@ -0,0 +1,36 @@
+import { Switch as HeadlessSwitch } from "@headlessui/react";
+import clsx from "clsx";
+import { Fragment } from "react";
+
+interface SwitchProps {
+ enabled: boolean;
+ setEnabled: (enabled: boolean) => void;
+ className?: string;
+}
+
+export function Switch({ enabled, setEnabled, className }: SwitchProps) {
+ return (
+
+ {({ checked, disabled }) => (
+
+ )}
+
+ );
+}
+
+export default Switch;
diff --git a/frontend/libs/components/switch/tsconfig.json b/frontend/libs/components/switch/tsconfig.json
new file mode 100644
index 0000000000..b3d19d8f5e
--- /dev/null
+++ b/frontend/libs/components/switch/tsconfig.json
@@ -0,0 +1,13 @@
+{
+ "files": [],
+ "include": [],
+ "references": [
+ {
+ "path": "./tsconfig.lib.json"
+ },
+ {
+ "path": "./tsconfig.spec.json"
+ }
+ ],
+ "extends": "../../../tsconfig.base.json"
+}
diff --git a/frontend/libs/components/switch/tsconfig.lib.json b/frontend/libs/components/switch/tsconfig.lib.json
new file mode 100644
index 0000000000..f0782e3dd8
--- /dev/null
+++ b/frontend/libs/components/switch/tsconfig.lib.json
@@ -0,0 +1,45 @@
+{
+ "extends": "../../../tsconfig.base.json",
+ "compilerOptions": {
+ "outDir": "dist",
+ "types": [
+ "node",
+ "@nx/react/typings/cssmodule.d.ts",
+ "@nx/react/typings/image.d.ts",
+ "vite/client"
+ ],
+ "rootDir": "src",
+ "jsx": "react-jsx",
+ "tsBuildInfoFile": "dist/tsconfig.lib.tsbuildinfo"
+ },
+ "exclude": [
+ "out-tsc",
+ "dist",
+ "**/*.spec.ts",
+ "**/*.test.ts",
+ "**/*.spec.tsx",
+ "**/*.test.tsx",
+ "**/*.spec.js",
+ "**/*.test.js",
+ "**/*.spec.jsx",
+ "**/*.test.jsx",
+ "vite.config.ts",
+ "vite.config.mts",
+ "vitest.config.ts",
+ "vitest.config.mts",
+ "src/**/*.test.ts",
+ "src/**/*.spec.ts",
+ "src/**/*.test.tsx",
+ "src/**/*.spec.tsx",
+ "src/**/*.test.js",
+ "src/**/*.spec.js",
+ "src/**/*.test.jsx",
+ "src/**/*.spec.jsx"
+ ],
+ "include": [
+ "src/**/*.js",
+ "src/**/*.jsx",
+ "src/**/*.ts",
+ "src/**/*.tsx"
+ ]
+}
diff --git a/frontend/libs/components/switch/tsconfig.spec.json b/frontend/libs/components/switch/tsconfig.spec.json
new file mode 100644
index 0000000000..18b7de51b8
--- /dev/null
+++ b/frontend/libs/components/switch/tsconfig.spec.json
@@ -0,0 +1,34 @@
+{
+ "extends": "../../../tsconfig.base.json",
+ "compilerOptions": {
+ "outDir": "./out-tsc/vitest",
+ "types": [
+ "vitest/globals",
+ "vitest/importMeta",
+ "vite/client",
+ "node",
+ "vitest"
+ ],
+ "jsx": "react-jsx"
+ },
+ "include": [
+ "vite.config.ts",
+ "vite.config.mts",
+ "vitest.config.ts",
+ "vitest.config.mts",
+ "src/**/*.test.ts",
+ "src/**/*.spec.ts",
+ "src/**/*.test.tsx",
+ "src/**/*.spec.tsx",
+ "src/**/*.test.js",
+ "src/**/*.spec.js",
+ "src/**/*.test.jsx",
+ "src/**/*.spec.jsx",
+ "src/**/*.d.ts"
+ ],
+ "references": [
+ {
+ "path": "./tsconfig.lib.json"
+ }
+ ]
+}
diff --git a/frontend/libs/components/switch/vite.config.ts b/frontend/libs/components/switch/vite.config.ts
new file mode 100644
index 0000000000..63d9fe0a36
--- /dev/null
+++ b/frontend/libs/components/switch/vite.config.ts
@@ -0,0 +1,49 @@
+///
+import { defineConfig } from 'vite';
+import react from '@vitejs/plugin-react';
+import dts from 'vite-plugin-dts';
+import * as path from 'path';
+
+export default defineConfig(() => ({
+ root: __dirname,
+ cacheDir: '../../../node_modules/.vite/libs/components/switch',
+ plugins: [react(), dts({ entryRoot: 'src', tsconfigPath: path.join(__dirname, 'tsconfig.lib.json') })],
+ // Uncomment this if you are using workers.
+ // worker: {
+ // plugins: [ nxViteTsPaths() ],
+ // },
+ // Configuration for building your library.
+ // See: https://vitejs.dev/guide/build.html#library-mode
+ build: {
+ outDir: './dist',
+ emptyOutDir: true,
+ reportCompressedSize: true,
+ commonjsOptions: {
+ transformMixedEsModules: true,
+ },
+ lib: {
+ // Could also be a dictionary or array of multiple entry points.
+ entry: 'src/index.ts',
+ name: '@storyteller/ui-switch',
+ fileName: 'index',
+ // Change this to the formats you want to support.
+ // Don't forget to update your package.json as well.
+ formats: ['es' as const]
+ },
+ rollupOptions: {
+ // External packages that should not be bundled into your library.
+ external: ['react','react-dom','react/jsx-runtime']
+ },
+ },
+ test: {
+ watch: false,
+ globals: true,
+ environment: 'jsdom',
+ include: ['{src,tests}/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
+ reporters: ['default'],
+ coverage: {
+ reportsDirectory: './test-output/vitest/coverage',
+ provider: 'v8' as const,
+ }
+ },
+}));
diff --git a/frontend/libs/tauri-api/src/index.ts b/frontend/libs/tauri-api/src/index.ts
index e8f9c851bd..ff95a96ed2 100644
--- a/frontend/libs/tauri-api/src/index.ts
+++ b/frontend/libs/tauri-api/src/index.ts
@@ -1,4 +1,5 @@
-
-export * from './lib/settings/GetAppPreferences.js';
-export * from './lib/settings/UpdateAppPreference.js';
-export * from './lib/sora/CheckSoraSession.js';
+export * from "./lib/settings/GetAppPreferences.js";
+export * from "./lib/settings/UpdateAppPreference.js";
+export * from "./lib/sora/CheckSoraSession.js";
+export * from "./lib/sora/useSoraLoginListener.js";
+export * from "./lib/sora/LogoutSoraSession.js";
diff --git a/frontend/libs/tauri-api/src/lib/sora/CheckSoraSession.ts b/frontend/libs/tauri-api/src/lib/sora/CheckSoraSession.ts
index 8d9b5831d8..69cc587692 100644
--- a/frontend/libs/tauri-api/src/lib/sora/CheckSoraSession.ts
+++ b/frontend/libs/tauri-api/src/lib/sora/CheckSoraSession.ts
@@ -1,8 +1,8 @@
import { invoke } from "@tauri-apps/api/core";
export interface CheckSoraSessionResult {
- state: SoraSessionState,
- maybe_account_email?: string,
+ state: SoraSessionState;
+ maybe_account_email?: string;
}
export enum SoraSessionState {
@@ -11,8 +11,8 @@ export enum SoraSessionState {
Valid = "valid",
}
-export const CheckSoraSession = async () : Promise => {
- let result = await invoke("check_sora_session_command");
+export const CheckSoraSession = async (): Promise => {
+ const result = await invoke("check_sora_session_command");
console.log(">>> sora result", result);
- return (result as CheckSoraSessionResult);
-}
+ return result as CheckSoraSessionResult;
+};
diff --git a/frontend/libs/tauri-api/src/lib/sora/LogoutSoraSession.ts b/frontend/libs/tauri-api/src/lib/sora/LogoutSoraSession.ts
new file mode 100644
index 0000000000..c52f9ae5d0
--- /dev/null
+++ b/frontend/libs/tauri-api/src/lib/sora/LogoutSoraSession.ts
@@ -0,0 +1,4 @@
+export const LogoutSoraSession = async (): Promise => {
+ // Replace with real Tauri command to logout Sora session - BFlat
+ return new Promise((resolve) => setTimeout(resolve, 500));
+};
diff --git a/frontend/libs/tauri-api/src/lib/sora/useSoraLoginListener.ts b/frontend/libs/tauri-api/src/lib/sora/useSoraLoginListener.ts
new file mode 100644
index 0000000000..40cb23a8d0
--- /dev/null
+++ b/frontend/libs/tauri-api/src/lib/sora/useSoraLoginListener.ts
@@ -0,0 +1,30 @@
+import { useEffect } from "react";
+import { listen } from "@tauri-apps/api/event";
+
+type SoraLoginSuccessPayload = {
+ // TODO
+};
+
+export function useSoraLoginListener(
+ onSuccess: (payload: SoraLoginSuccessPayload) => void
+) {
+ useEffect(() => {
+ let unlisten: () => void;
+
+ const setupListener = async () => {
+ const stop = await listen(
+ "sora-login-success",
+ (event) => {
+ onSuccess(event.payload);
+ }
+ );
+ unlisten = stop;
+ };
+
+ setupListener();
+
+ return () => {
+ if (unlisten) unlisten();
+ };
+ }, [onSuccess]);
+}
diff --git a/frontend/package-lock.json b/frontend/package-lock.json
index b1ebb44995..5eab2998ff 100644
--- a/frontend/package-lock.json
+++ b/frontend/package-lock.json
@@ -2234,6 +2234,10 @@
"@tauri-apps/plugin-dialog": "^2.2.1"
}
},
+ "libs/components/switch": {
+ "name": "@storyteller/ui-switch",
+ "version": "0.0.1"
+ },
"libs/components/tab-selector": {
"name": "@storyteller/ui-tab-selector",
"version": "0.0.1"
@@ -10340,6 +10344,10 @@
"resolved": "libs/components/settings-modal",
"link": true
},
+ "node_modules/@storyteller/ui-switch": {
+ "resolved": "libs/components/switch",
+ "link": true
+ },
"node_modules/@storyteller/ui-tab-selector": {
"resolved": "libs/components/tab-selector",
"link": true
diff --git a/frontend/tsconfig.json b/frontend/tsconfig.json
index 32242d626e..8c9879f034 100644
--- a/frontend/tsconfig.json
+++ b/frontend/tsconfig.json
@@ -68,6 +68,9 @@
},
{
"path": "./libs/components/login-modal"
+ },
+ {
+ "path": "./libs/components/switch"
}
]
}