From bb5bb58dd14d523e75139b67d579b19e91e1c809 Mon Sep 17 00:00:00 2001 From: mjarkk Date: Mon, 15 Jul 2024 17:21:11 +0200 Subject: [PATCH] Add mobile view --- go/web_server.go | 2 +- src/components/App.tsx | 27 +++++++++++++++++++++------ src/components/show/Show.tsx | 4 +--- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/go/web_server.go b/go/web_server.go index 3fab3c7..7ee5134 100644 --- a/go/web_server.go +++ b/go/web_server.go @@ -167,7 +167,7 @@ func StartWebserver(dist embed.FS, opts StartWebserverOptions) { searchValue := strings.TrimSpace(c.Query("search")) if searchValue == "" { - // Do the quick path + // Take the quick path response := make([]*Email, len(emails)) diff --git a/src/components/App.tsx b/src/components/App.tsx index 38cc977..31bf3f9 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -1,5 +1,6 @@ import { Match, + Show, Switch, createContext, createEffect, @@ -14,8 +15,8 @@ import type { Accessor, Setter } from "solid-js" import { EmailEventsWebsocket } from "../services/websocket" import { fetch } from "../services/fetch" -const Show = lazy(() => - import("./show/Show").then((m) => ({ default: m.Show })), +const ShowEmail = lazy(() => + import("./show/Show").then((m) => ({ default: m.ShowEmail })), ) interface SelectedEmailActions { @@ -62,10 +63,13 @@ function throttleFn(fn: () => Promise): () => Promise { } } +const calculateIsMobile = () => window.innerWidth < 840 + export function App() { const [emails, setEmails] = createSignal>() const [selectedEmail, setSelectedEmail] = createSignal() const [searchValue, setSearchValue] = createSignal("") + const [isMobile, setIsMobile] = createSignal(calculateIsMobile()) const fetchEmails = throttleFn(async () => { let url = "/api/emails" @@ -86,12 +90,19 @@ export function App() { fetchEmails() }) + const onResize = () => { + const newIsMobile = calculateIsMobile() + if (newIsMobile !== isMobile()) setIsMobile(newIsMobile) + } + onMount(() => { emailsWebsocket.start() + window.addEventListener("resize", onResize) }) onCleanup(() => { emailsWebsocket.close() + window.removeEventListener("resize", onResize) }) const deleteSelected = async () => { @@ -119,6 +130,9 @@ export function App() { { set: setSearchValue }, ] + const showEmail = () => + emails() !== undefined && selectedEmail() !== undefined + return ( @@ -131,9 +145,10 @@ export function App() { /> } > - + + + + selectedEmail()!} @@ -165,7 +180,7 @@ function LeftOverviewRightEmail({ emails }: LeftOverviewRightEmailProps) { > - + ) } diff --git a/src/components/show/Show.tsx b/src/components/show/Show.tsx index 8d2bd8c..31f3f67 100644 --- a/src/components/show/Show.tsx +++ b/src/components/show/Show.tsx @@ -6,9 +6,7 @@ import { Header } from "./Header" import { Attachments } from "./Attachments" import { Body } from "./Body" -export interface ShowProps {} - -export function Show({}: ShowProps) { +export function ShowEmail() { const [email] = useContext(SelectedEmailContext) const mustEmail = () => email()!