1
1
import {
2
2
Match ,
3
+ Show ,
3
4
Switch ,
4
5
createContext ,
5
6
createEffect ,
@@ -14,8 +15,8 @@ import type { Accessor, Setter } from "solid-js"
14
15
import { EmailEventsWebsocket } from "../services/websocket"
15
16
import { fetch } from "../services/fetch"
16
17
17
- const Show = lazy ( ( ) =>
18
- import ( "./show/Show" ) . then ( ( m ) => ( { default : m . Show } ) ) ,
18
+ const ShowEmail = lazy ( ( ) =>
19
+ import ( "./show/Show" ) . then ( ( m ) => ( { default : m . ShowEmail } ) ) ,
19
20
)
20
21
21
22
interface SelectedEmailActions {
@@ -62,10 +63,13 @@ function throttleFn(fn: () => Promise<void>): () => Promise<void> {
62
63
}
63
64
}
64
65
66
+ const calculateIsMobile = ( ) => window . innerWidth < 840
67
+
65
68
export function App ( ) {
66
69
const [ emails , setEmails ] = createSignal < Array < EmailBase > > ( )
67
70
const [ selectedEmail , setSelectedEmail ] = createSignal < EmailBase > ( )
68
71
const [ searchValue , setSearchValue ] = createSignal < string > ( "" )
72
+ const [ isMobile , setIsMobile ] = createSignal ( calculateIsMobile ( ) )
69
73
70
74
const fetchEmails = throttleFn ( async ( ) => {
71
75
let url = "/api/emails"
@@ -86,12 +90,19 @@ export function App() {
86
90
fetchEmails ( )
87
91
} )
88
92
93
+ const onResize = ( ) => {
94
+ const newIsMobile = calculateIsMobile ( )
95
+ if ( newIsMobile !== isMobile ( ) ) setIsMobile ( newIsMobile )
96
+ }
97
+
89
98
onMount ( ( ) => {
90
99
emailsWebsocket . start ( )
100
+ window . addEventListener ( "resize" , onResize )
91
101
} )
92
102
93
103
onCleanup ( ( ) => {
94
104
emailsWebsocket . close ( )
105
+ window . removeEventListener ( "resize" , onResize )
95
106
} )
96
107
97
108
const deleteSelected = async ( ) => {
@@ -119,6 +130,9 @@ export function App() {
119
130
{ set : setSearchValue } ,
120
131
]
121
132
133
+ const showEmail = ( ) =>
134
+ emails ( ) !== undefined && selectedEmail ( ) !== undefined
135
+
122
136
return (
123
137
< SelectedEmailContext . Provider value = { selectedEmailContext ( ) } >
124
138
< SearchContext . Provider value = { searchContext ( ) } >
@@ -131,9 +145,10 @@ export function App() {
131
145
/>
132
146
}
133
147
>
134
- < Match
135
- when = { emails ( ) !== undefined && selectedEmail ( ) !== undefined }
136
- >
148
+ < Match when = { showEmail ( ) && isMobile ( ) } >
149
+ < ShowEmail />
150
+ </ Match >
151
+ < Match when = { showEmail ( ) } >
137
152
< LeftOverviewRightEmail
138
153
emails = { emails }
139
154
selectedEmail = { ( ) => selectedEmail ( ) ! }
@@ -165,7 +180,7 @@ function LeftOverviewRightEmail({ emails }: LeftOverviewRightEmailProps) {
165
180
>
166
181
< Overview emails = { emails } />
167
182
</ div >
168
- < Show />
183
+ < ShowEmail />
169
184
</ div >
170
185
)
171
186
}
0 commit comments