Skip to content

Commit f6d56c2

Browse files
committed
feat: basic modal setup
1 parent 1577b29 commit f6d56c2

File tree

6 files changed

+42
-34
lines changed

6 files changed

+42
-34
lines changed

GUI/ETVR/src/app.tsx

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
import { ColorModeScript, HopeProvider, injectCriticalStyle, Button } from '@hope-ui/core'
1+
import {
2+
ColorModeScript,
3+
HopeProvider,
4+
injectCriticalStyle,
5+
HStack,
6+
Button,
7+
Text,
8+
} from '@hope-ui/core'
29
import { invoke } from '@tauri-apps/api/tauri'
310
import { appWindow } from '@tauri-apps/api/window'
411
import { onMount, Suspense } from 'solid-js'
512
import AppRoutes from './routes/Routes'
13+
import ModalMenu from '@components/Modal'
614
import NewWindow from '@components/NewWindow'
715

816
const handleTitlebar = () => {
@@ -52,6 +60,19 @@ const Menu = () => {
5260
)
5361
}
5462

63+
const ModalHandler = () => {
64+
return (
65+
<ModalMenu initialFocus="#first-field">
66+
<Text mb={4}>The content of the Modal.</Text>
67+
<HStack justifyContent="flex-end" spacing={4}>
68+
<Button id="initial-focus" _focus={{ color: 'red' }}>
69+
Action
70+
</Button>
71+
</HStack>
72+
</ModalMenu>
73+
)
74+
}
75+
5576
const App = () => {
5677
const ref = document.getElementById('titlebar')
5778
injectCriticalStyle()
@@ -68,6 +89,7 @@ const App = () => {
6889
<NewWindow ref={ref} name="test" cssVariable="--menu-visibility">
6990
<Menu />
7091
</NewWindow>
92+
<ModalHandler />
7193
</Suspense>
7294
</HopeProvider>
7395
</div>

GUI/ETVR/src/components/Camera/index.tsx

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { Image } from '@hope-ui/core'
1+
import { IconButton } from '@hope-ui/core'
2+
import { FaSolidGear } from 'solid-icons/fa'
23
import CameraStatusIndicator from './CameraIndicator/CameraIndicator'
3-
import icons from '@assets/images'
44
import { ICamera } from '@src/store/mdns/mdns'
5+
import { setOpenModal } from '@src/store/ui/ui'
56
import { ActiveStatus } from '@src/utils/utils'
67

78
// TODO: switch camera based on status
@@ -40,13 +41,14 @@ export const Camera = (props: ICamera) => {
4041
<div>{props.type.toLocaleLowerCase()}</div>
4142
</div>
4243
<div class="flex text-[#FFFF] justify-end ">
43-
<Image
44-
src={icons.gearSolid}
45-
objectFit={'contain'}
46-
alt="logo"
47-
width="20px"
48-
height="100%"
49-
/>
44+
<IconButton
45+
aria-label="Settings"
46+
variant="plain"
47+
colorScheme="neutral"
48+
size="lg"
49+
onClick={() => setOpenModal(true)}>
50+
<FaSolidGear />
51+
</IconButton>
5052
</div>
5153
</div>
5254
</div>

GUI/ETVR/src/components/Modal/index.tsx

+5-22
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,27 @@
1-
import { Button, HStack, Modal, Text } from '@hope-ui/core'
2-
import { children, createSignal, createEffect, Show, onMount } from 'solid-js'
1+
import { HStack, Modal } from '@hope-ui/core'
2+
import { children, createEffect } from 'solid-js'
33
import { openModalStatus } from '@src/store/ui/selectors'
44
import { setOpenModal, type IModalMenu } from '@src/store/ui/ui'
55
import './styles.css'
66

77
const ModalMenu = (props: IModalMenu) => {
8-
const [ref, setRef] = createSignal<HTMLElement>()
98
const Children = children(() => props.children)
10-
const clickOutside = (e: MouseEvent) => {
11-
if (e.target instanceof HTMLElement) {
12-
if (ref() && (ref()?.contains(e.target) || ref()?.isSameNode(e.target))) return
13-
console.log('clicked outside')
14-
setOpenModal(false)
15-
}
16-
}
179
createEffect(() => {
18-
if (openModalStatus()) {
19-
document.addEventListener('click', clickOutside)
20-
return
21-
}
22-
document.removeEventListener('click', clickOutside)
10+
console.log('openModalStatus:', openModalStatus())
2311
})
2412
return (
2513
<>
2614
<Modal
2715
isOpen={openModalStatus() ?? false}
2816
onClose={() => setOpenModal(false)}
29-
initialFocusSelector="#initial-focus">
17+
initialFocusSelector={props.initialFocus}>
3018
<Modal.Overlay />
3119
<Modal.Content p={4}>
3220
<HStack justifyContent="space-between" mb={4}>
3321
<Modal.Heading fontWeight="semibold">Title</Modal.Heading>
3422
<Modal.CloseButton />
3523
</HStack>
36-
<Text mb={4}>The content of the Modal.</Text>
37-
<HStack justifyContent="flex-end" spacing={4}>
38-
<Button id="initial-focus" _focus={{ color: 'red' }}>
39-
Action
40-
</Button>
41-
</HStack>
24+
{Children()}
4225
</Modal.Content>
4326
</Modal>
4427
</>

GUI/ETVR/src/pages/Home/index.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { CAMERA_VIEW_MODE } from '@src/utils/enums'
88

99
const Main = () => {
1010
const [selectMode, setSelectMode] = createSignal(CAMERA_VIEW_MODE.GRIP)
11-
1211
return (
1312
<div class="py-[40px]">
1413
<div>

GUI/ETVR/src/store/mdns/mdns.ts

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export enum CameraType {
1515
export interface ICamera {
1616
status: CameraStatus
1717
type: CameraType
18+
name: string
1819
address: string
1920
activeCameraSection: string
2021
}
@@ -29,6 +30,7 @@ const staticCamerasGenerator = new Array(5).fill(0).map(() => ({
2930
status: CameraStatus.LOADING,
3031
type: CameraType.WIRELESS,
3132
address: '192.168.0.204',
33+
name: 'left-eye',
3234
activeCameraSection: 'left eye',
3335
}))
3436

GUI/ETVR/src/store/ui/ui.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export interface INewMenu {
2020

2121
export interface IModalMenu {
2222
children: JSXElement
23-
ref: HTMLElement | null
23+
initialFocus?: string
2424
}
2525

2626
interface IUiStore {

0 commit comments

Comments
 (0)