forked from Shiloh/remnantchat
feat: render top bar
This commit is contained in:
parent
73daf3ddb3
commit
71ecc37d89
@ -1,9 +1,13 @@
|
|||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useMemo, useState } from 'react'
|
||||||
import { Routes, Route } from 'react-router-dom'
|
import { Routes, Route } from 'react-router-dom'
|
||||||
import { v4 as uuid } from 'uuid'
|
import { v4 as uuid } from 'uuid'
|
||||||
import localforage from 'localforage'
|
import localforage from 'localforage'
|
||||||
|
import AppBar from '@mui/material/AppBar'
|
||||||
|
import Toolbar from '@mui/material/Toolbar'
|
||||||
import Box from '@mui/material/Box'
|
import Box from '@mui/material/Box'
|
||||||
|
import Typography from '@mui/material/Typography'
|
||||||
|
|
||||||
|
import { ShellContext } from 'ShellContext'
|
||||||
import { Home } from 'pages/Home/'
|
import { Home } from 'pages/Home/'
|
||||||
import { PublicRoom } from 'pages/PublicRoom/'
|
import { PublicRoom } from 'pages/PublicRoom/'
|
||||||
import { UserSettings } from 'models/settings'
|
import { UserSettings } from 'models/settings'
|
||||||
@ -24,6 +28,9 @@ function Bootstrap({
|
|||||||
const [hasLoadedSettings, setHasLoadedSettings] = useState(false)
|
const [hasLoadedSettings, setHasLoadedSettings] = useState(false)
|
||||||
const [settings, setSettings] = useState({ userId: getUuid() })
|
const [settings, setSettings] = useState({ userId: getUuid() })
|
||||||
const { userId } = settings
|
const { userId } = settings
|
||||||
|
const [title, setTitle] = useState('')
|
||||||
|
|
||||||
|
const shellContextValue = useMemo(() => ({ setTitle }), [setTitle])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
;(async () => {
|
;(async () => {
|
||||||
@ -48,19 +55,29 @@ function Bootstrap({
|
|||||||
}, [hasLoadedSettings, persistedStorage, settings, userId])
|
}, [hasLoadedSettings, persistedStorage, settings, userId])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box className="Chitchatter" sx={{ height: '100vh' }}>
|
<ShellContext.Provider value={shellContextValue}>
|
||||||
{hasLoadedSettings ? (
|
<Box
|
||||||
<Routes>
|
className="Chitchatter"
|
||||||
{['/', '/index.html'].map(path => (
|
sx={{ height: '100vh', display: 'flex', flexDirection: 'column' }}
|
||||||
<Route key={path} path={path} element={<Home />} />
|
>
|
||||||
))}
|
<AppBar position="relative">
|
||||||
<Route
|
<Toolbar variant="regular">
|
||||||
path="/public/:roomId"
|
<Typography sx={{ fontWeight: 'bold' }}>{title}</Typography>
|
||||||
element={<PublicRoom userId={userId} />}
|
</Toolbar>
|
||||||
/>
|
</AppBar>
|
||||||
</Routes>
|
{hasLoadedSettings ? (
|
||||||
) : null}
|
<Routes>
|
||||||
</Box>
|
{['/', '/index.html'].map(path => (
|
||||||
|
<Route key={path} path={path} element={<Home />} />
|
||||||
|
))}
|
||||||
|
<Route
|
||||||
|
path="/public/:roomId"
|
||||||
|
element={<PublicRoom userId={userId} />}
|
||||||
|
/>
|
||||||
|
</Routes>
|
||||||
|
) : null}
|
||||||
|
</Box>
|
||||||
|
</ShellContext.Provider>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
9
src/ShellContext.ts
Normal file
9
src/ShellContext.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import { createContext, Dispatch, SetStateAction } from 'react'
|
||||||
|
|
||||||
|
interface ShellContextProps {
|
||||||
|
setTitle: Dispatch<SetStateAction<string>>
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ShellContext = createContext<ShellContextProps>({
|
||||||
|
setTitle: () => {},
|
||||||
|
})
|
@ -2,7 +2,6 @@ import React, { useState } from 'react'
|
|||||||
import { v4 as uuid } from 'uuid'
|
import { v4 as uuid } from 'uuid'
|
||||||
import Box from '@mui/material/Box'
|
import Box from '@mui/material/Box'
|
||||||
import FormControl from '@mui/material/FormControl'
|
import FormControl from '@mui/material/FormControl'
|
||||||
import Typography from '@mui/material/Typography'
|
|
||||||
import Stack from '@mui/material/Stack'
|
import Stack from '@mui/material/Stack'
|
||||||
import TextField from '@mui/material/TextField'
|
import TextField from '@mui/material/TextField'
|
||||||
import Fab from '@mui/material/Fab'
|
import Fab from '@mui/material/Fab'
|
||||||
@ -99,7 +98,6 @@ export function Room({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Box className="h-full p-4 flex flex-col">
|
<Box className="h-full p-4 flex flex-col">
|
||||||
<Typography>Room ID: {roomId}</Typography>
|
|
||||||
<ChatTranscript
|
<ChatTranscript
|
||||||
messageLog={messageLog}
|
messageLog={messageLog}
|
||||||
userId={userId}
|
userId={userId}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import React, { useState } from 'react'
|
import React, { useEffect, useContext, useState } from 'react'
|
||||||
import { useNavigate } from 'react-router-dom'
|
import { useNavigate } from 'react-router-dom'
|
||||||
import Button from '@mui/material/Button'
|
import Button from '@mui/material/Button'
|
||||||
import Box from '@mui/material/Box'
|
import Box from '@mui/material/Box'
|
||||||
@ -7,10 +7,17 @@ import Typography from '@mui/material/Typography'
|
|||||||
import TextField from '@mui/material/TextField'
|
import TextField from '@mui/material/TextField'
|
||||||
import { v4 as uuid } from 'uuid'
|
import { v4 as uuid } from 'uuid'
|
||||||
|
|
||||||
|
import { ShellContext } from 'ShellContext'
|
||||||
|
|
||||||
export function Home() {
|
export function Home() {
|
||||||
|
const { setTitle } = useContext(ShellContext)
|
||||||
const [roomName, setRoomName] = useState(uuid())
|
const [roomName, setRoomName] = useState(uuid())
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setTitle('Chitchatter')
|
||||||
|
}, [setTitle])
|
||||||
|
|
||||||
const handleRoomNameChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
const handleRoomNameChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
const { value } = event.target
|
const { value } = event.target
|
||||||
setRoomName(value)
|
setRoomName(value)
|
||||||
@ -23,8 +30,7 @@ export function Home() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Box className="Home">
|
<Box className="Home">
|
||||||
<header className="max-w-3xl text-center mx-auto">
|
<header className="max-w-3xl text-center mx-auto mt-8">
|
||||||
<Typography variant="h1">chitchatter</Typography>
|
|
||||||
<Typography variant="body1">
|
<Typography variant="body1">
|
||||||
This is a communication tool that is free, open source, and designed
|
This is a communication tool that is free, open source, and designed
|
||||||
for maximum security. All communication between you and your online
|
for maximum security. All communication between you and your online
|
||||||
|
@ -1,11 +1,20 @@
|
|||||||
|
import { useContext, useEffect } from 'react'
|
||||||
import { Room } from 'components/Room'
|
import { Room } from 'components/Room'
|
||||||
import { useParams } from 'react-router-dom'
|
import { useParams } from 'react-router-dom'
|
||||||
|
|
||||||
|
import { ShellContext } from 'ShellContext'
|
||||||
|
|
||||||
interface PublicRoomProps {
|
interface PublicRoomProps {
|
||||||
userId: string
|
userId: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export function PublicRoom({ userId }: PublicRoomProps) {
|
export function PublicRoom({ userId }: PublicRoomProps) {
|
||||||
const { roomId = '' } = useParams()
|
const { roomId = '' } = useParams()
|
||||||
|
const { setTitle } = useContext(ShellContext)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setTitle(`Room: ${roomId}`)
|
||||||
|
}, [roomId, setTitle])
|
||||||
|
|
||||||
return <Room userId={userId} roomId={roomId} />
|
return <Room userId={userId} roomId={roomId} />
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user