summaryrefslogtreecommitdiff
path: root/frontend/src/components/DeckyGlobalComponentsState.tsx
diff options
context:
space:
mode:
authorAAGaming <aagaming@riseup.net>2024-10-04 23:59:53 -0400
committerAAGaming <aagaming@riseup.net>2024-10-11 15:05:15 -0400
commit7b32df09487383897927356547f1ba5a73e8cc94 (patch)
tree18932621c4d2ac794e5fd1b5cb6968c4554b66e0 /frontend/src/components/DeckyGlobalComponentsState.tsx
parent306b0ff8d6206a912478ed1e3d3dbf82b8a85c41 (diff)
downloaddecky-loader-7b32df09487383897927356547f1ba5a73e8cc94.tar.gz
decky-loader-7b32df09487383897927356547f1ba5a73e8cc94.zip
Add routerhook for desktop UI and a basic sidebar menu for Decky in desktop UI
Diffstat (limited to 'frontend/src/components/DeckyGlobalComponentsState.tsx')
-rw-r--r--frontend/src/components/DeckyGlobalComponentsState.tsx27
1 files changed, 19 insertions, 8 deletions
diff --git a/frontend/src/components/DeckyGlobalComponentsState.tsx b/frontend/src/components/DeckyGlobalComponentsState.tsx
index 475d1e4a..4088f7b1 100644
--- a/frontend/src/components/DeckyGlobalComponentsState.tsx
+++ b/frontend/src/components/DeckyGlobalComponentsState.tsx
@@ -1,12 +1,17 @@
import { FC, ReactNode, createContext, useContext, useEffect, useState } from 'react';
+import { UIMode } from '../enums';
+
interface PublicDeckyGlobalComponentsState {
- components: Map<string, FC>;
+ components: Map<UIMode, Map<string, FC>>;
}
export class DeckyGlobalComponentsState {
// TODO a set would be better
- private _components = new Map<string, FC>();
+ private _components = new Map<UIMode, Map<string, FC>>([
+ [UIMode.BigPicture, new Map()],
+ [UIMode.Desktop, new Map()],
+ ]);
public eventBus = new EventTarget();
@@ -14,13 +19,19 @@ export class DeckyGlobalComponentsState {
return { components: this._components };
}
- addComponent(path: string, component: FC) {
- this._components.set(path, component);
+ addComponent(path: string, component: FC, uiMode: UIMode) {
+ const components = this._components.get(uiMode);
+ if (!components) throw new Error(`UI mode ${uiMode} not supported.`);
+
+ components.set(path, component);
this.notifyUpdate();
}
- removeComponent(path: string) {
- this._components.delete(path);
+ removeComponent(path: string, uiMode: UIMode) {
+ const components = this._components.get(uiMode);
+ if (!components) throw new Error(`UI mode ${uiMode} not supported.`);
+
+ components.delete(path);
this.notifyUpdate();
}
@@ -30,8 +41,8 @@ export class DeckyGlobalComponentsState {
}
interface DeckyGlobalComponentsContext extends PublicDeckyGlobalComponentsState {
- addComponent(path: string, component: FC): void;
- removeComponent(path: string): void;
+ addComponent(path: string, component: FC, uiMode: UIMode): void;
+ removeComponent(path: string, uiMode: UIMode): void;
}
const DeckyGlobalComponentsContext = createContext<DeckyGlobalComponentsContext>(null as any);