@@ -4,13 +4,11 @@ import { useState, useEffect } from "react"
44import HomeScreen from "./components/homescreen"
55import ChatView from "./components/chatview"
66import Header from "./components/header"
7- import LogView from "./components/logview"
87import Sidebar from "./components/sidebar"
98import { ThemeProvider } from "next-themes"
10- import { InvitePopup } from "./components/invitepopup"
119import { API , initApi , type ChannelInfo } from "./lib/api"
12- import { generate as generateName } from 'yet-another-name-generator'
1310import { log } from "./lib/log"
11+ import { useIsDesktop } from "./hooks/use-media-query"
1412
1513export default function AppWrapper ( ) {
1614 const [ api , setApi ] = useState < API | null > ( null )
@@ -45,13 +43,9 @@ function Spinner() {
4543}
4644
4745function SplashScreen ( { children } : React . PropsWithChildren ) {
48- const [ showLogView , setShowLogView ] = useState ( false )
4946 return (
5047 < div className = "flex flex-col flex-grow" >
51- < Header
52- onLogsClick = { ( ) => setShowLogView ( ! showLogView ) }
53- />
54- { showLogView && < LogView onClose = { ( ) => setShowLogView ( false ) } /> }
48+ < Header />
5549 < div className = "flex items-center justify-center" >
5650 { children }
5751 </ div >
@@ -68,28 +62,27 @@ function App({ api }: AppProps) {
6862 const [ currentView , setCurrentView ] = useState < "home" | "chat" > ( "home" )
6963 const [ channels , setChannels ] = useState < ChannelInfo [ ] > ( [ ] )
7064 const [ activeChannel , setActiveChannel ] = useState < string | null > ( null )
71- const [ showLogView , setShowLogView ] = useState ( false )
72- const [ nickname , setNickname ] = useState ( generateName ( ) )
73- const [ showInvitePopup , setShowInvitePopup ] = useState ( false )
7465 const [ showSidebar , setShowSidebar ] = useState ( false )
7566
76- const joinChannel = async ( ticket : string ) => {
67+ const joinChannel = ( ticket : string , nickname : string ) => {
7768 try {
78- const channel = await api . joinChannel ( ticket , nickname )
69+ const channel = api . joinChannel ( ticket , nickname )
7970 setChannels ( ( prevChannels ) => [ ...prevChannels , channel ] )
80- setActiveChannel ( channel . id )
8171 setCurrentView ( "chat" )
72+ setActiveChannel ( channel . id )
73+ setShowSidebar ( true )
8274 } catch ( error ) {
8375 log . error ( "Failed to join channel" , error )
8476 }
8577 }
8678
87- const createChannel = async ( ) => {
79+ const createChannel = ( nickname : string ) => {
8880 try {
89- const channel = await api . createChannel ( nickname )
81+ const channel = api . createChannel ( nickname )
9082 setChannels ( ( prevChannels ) => [ ...prevChannels , channel ] )
9183 setActiveChannel ( channel . id )
9284 setCurrentView ( "chat" )
85+ setShowSidebar ( true )
9386 } catch ( error ) {
9487 log . error ( "Failed to create channel" , error )
9588 }
@@ -115,14 +108,16 @@ function App({ api }: AppProps) {
115108 setShowSidebar ( true )
116109 }
117110
111+ const isDesktop = useIsDesktop ( )
112+
118113 let title
119114 if ( activeChannel ) {
120115 title = '#' + channels . find ( ( c ) => c . id === activeChannel ) ?. name
121116 }
122117
123118 return (
124119 < >
125- { ( currentView === "chat" || showSidebar ) && (
120+ { isDesktop && ( showSidebar ) && (
126121 < Sidebar
127122 channels = { channels }
128123 activeChannel = { activeChannel }
@@ -135,39 +130,17 @@ function App({ api }: AppProps) {
135130 ) }
136131 < div className = "flex flex-col flex-grow" >
137132 < Header
138- onLogsClick = { ( ) => setShowLogView ( ! showLogView ) }
139133 title = { title }
140- onInviteClick = { activeChannel ? ( ( ) => setShowInvitePopup ( true ) ) : undefined }
141134 />
142135 { currentView === "home" && (
143136 < HomeScreen
144- name = { nickname }
145- onSetName = { setNickname }
146- onJoin = { ( ticket ) => {
147- joinChannel ( ticket )
148- setShowSidebar ( false )
149- } }
150- onCreate = { ( ) => {
151- createChannel ( )
152- setShowSidebar ( false )
153- } }
137+ onJoin = { joinChannel }
138+ onCreate = { createChannel }
154139 />
155140 ) }
156141 { currentView === "chat" && activeChannel && (
157142 < ChatView api = { api } channel = { activeChannel } onClose = { ( ) => closeChannel ( activeChannel ) } />
158143 ) }
159- { showLogView && < LogView onClose = { ( ) => setShowLogView ( false ) } /> }
160- { showInvitePopup && activeChannel && (
161- < InvitePopup
162- open = { showInvitePopup }
163- onOpenChange = { ( x ) => {
164- console . log ( "openchange" , x )
165- setShowInvitePopup ( x )
166- } }
167- channel = { channels . find ( ( c ) => c . id === activeChannel ) ?. name || "" }
168- getTicket = { ( opts ) => api . getTicket ( activeChannel ! , opts ) }
169- />
170- ) }
171144 </ div >
172145 </ >
173146 )
0 commit comments