Skip to content

Commit bb5bb58

Browse files
committed
Add mobile view
1 parent 7bd2cb0 commit bb5bb58

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

go/web_server.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func StartWebserver(dist embed.FS, opts StartWebserverOptions) {
167167
searchValue := strings.TrimSpace(c.Query("search"))
168168

169169
if searchValue == "" {
170-
// Do the quick path
170+
// Take the quick path
171171

172172
response := make([]*Email, len(emails))
173173

src/components/App.tsx

+21-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
Match,
3+
Show,
34
Switch,
45
createContext,
56
createEffect,
@@ -14,8 +15,8 @@ import type { Accessor, Setter } from "solid-js"
1415
import { EmailEventsWebsocket } from "../services/websocket"
1516
import { fetch } from "../services/fetch"
1617

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 })),
1920
)
2021

2122
interface SelectedEmailActions {
@@ -62,10 +63,13 @@ function throttleFn(fn: () => Promise<void>): () => Promise<void> {
6263
}
6364
}
6465

66+
const calculateIsMobile = () => window.innerWidth < 840
67+
6568
export function App() {
6669
const [emails, setEmails] = createSignal<Array<EmailBase>>()
6770
const [selectedEmail, setSelectedEmail] = createSignal<EmailBase>()
6871
const [searchValue, setSearchValue] = createSignal<string>("")
72+
const [isMobile, setIsMobile] = createSignal(calculateIsMobile())
6973

7074
const fetchEmails = throttleFn(async () => {
7175
let url = "/api/emails"
@@ -86,12 +90,19 @@ export function App() {
8690
fetchEmails()
8791
})
8892

93+
const onResize = () => {
94+
const newIsMobile = calculateIsMobile()
95+
if (newIsMobile !== isMobile()) setIsMobile(newIsMobile)
96+
}
97+
8998
onMount(() => {
9099
emailsWebsocket.start()
100+
window.addEventListener("resize", onResize)
91101
})
92102

93103
onCleanup(() => {
94104
emailsWebsocket.close()
105+
window.removeEventListener("resize", onResize)
95106
})
96107

97108
const deleteSelected = async () => {
@@ -119,6 +130,9 @@ export function App() {
119130
{ set: setSearchValue },
120131
]
121132

133+
const showEmail = () =>
134+
emails() !== undefined && selectedEmail() !== undefined
135+
122136
return (
123137
<SelectedEmailContext.Provider value={selectedEmailContext()}>
124138
<SearchContext.Provider value={searchContext()}>
@@ -131,9 +145,10 @@ export function App() {
131145
/>
132146
}
133147
>
134-
<Match
135-
when={emails() !== undefined && selectedEmail() !== undefined}
136-
>
148+
<Match when={showEmail() && isMobile()}>
149+
<ShowEmail />
150+
</Match>
151+
<Match when={showEmail()}>
137152
<LeftOverviewRightEmail
138153
emails={emails}
139154
selectedEmail={() => selectedEmail()!}
@@ -165,7 +180,7 @@ function LeftOverviewRightEmail({ emails }: LeftOverviewRightEmailProps) {
165180
>
166181
<Overview emails={emails} />
167182
</div>
168-
<Show />
183+
<ShowEmail />
169184
</div>
170185
)
171186
}

src/components/show/Show.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ import { Header } from "./Header"
66
import { Attachments } from "./Attachments"
77
import { Body } from "./Body"
88

9-
export interface ShowProps {}
10-
11-
export function Show({}: ShowProps) {
9+
export function ShowEmail() {
1210
const [email] = useContext(SelectedEmailContext)
1311
const mustEmail = () => email()!
1412

0 commit comments

Comments
 (0)