From 59a7ab046bb14f0cb9fbd8cc3766841916aee869 Mon Sep 17 00:00:00 2001 From: jarvis2f <137974272+jarvis2f@users.noreply.github.com> Date: Tue, 24 Dec 2024 13:30:55 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=B1=20feat:=20Optimize=20mobile=20disp?= =?UTF-8?q?lay?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/components/chat-select.tsx | 2 +- web/src/components/file-card.tsx | 2 +- web/src/components/file-filters.tsx | 8 +++---- web/src/components/file-list.tsx | 23 ++++++++++---------- web/src/components/file-type-filter.tsx | 2 +- web/src/components/header.tsx | 29 ++++++++++++++++++++----- web/src/hooks/use-is-mobile.ts | 19 ++++++++++++++++ 7 files changed, 62 insertions(+), 23 deletions(-) create mode 100644 web/src/hooks/use-is-mobile.ts diff --git a/web/src/components/chat-select.tsx b/web/src/components/chat-select.tsx index 523e74b..fbbbad1 100644 --- a/web/src/components/chat-select.tsx +++ b/web/src/components/chat-select.tsx @@ -37,7 +37,7 @@ export default function ChatSelect({ disabled }: { disabled: boolean }) { variant="outline" role="combobox" aria-expanded={open} - className="w-[250px] justify-between" + className="w-full md:w-[250px] justify-between" > {selectedChat ? (
diff --git a/web/src/components/file-card.tsx b/web/src/components/file-card.tsx index 3b20d53..a774683 100644 --- a/web/src/components/file-card.tsx +++ b/web/src/components/file-card.tsx @@ -56,7 +56,7 @@ export function FileCard({ file }: FileCardProps) {

{file.name}

- {prettyBytes(file.size)} • {file.type} + {prettyBytes(file.size)} • {file.type} • {file.downloadStatus}
diff --git a/web/src/components/file-filters.tsx b/web/src/components/file-filters.tsx index e637b5b..416cc3f 100644 --- a/web/src/components/file-filters.tsx +++ b/web/src/components/file-filters.tsx @@ -39,14 +39,14 @@ export function FileFilters({ }: FileFiltersProps) { return (
-
+
onFiltersChange({ ...filters, search: e.target.value }) } - className="md:w-[300px]" + className="col-span-2 md:w-[300px]" /> - + @@ -78,7 +78,7 @@ export function FileFilters({
-
+
>(new Set()); const observerTarget = useRef(null); const [columns, setColumns] = useState(COLUMNS); @@ -110,16 +111,6 @@ export function FileList({ accountId, chatId }: FileListProps) { const { filters, handleFilterChange, isLoading, files, handleLoadMore } = useFiles(accountId, chatId); - useEffect(() => { - const checkMobile = () => { - setIsMobile(window.innerWidth < 768); - }; - - checkMobile(); - window.addEventListener("resize", checkMobile); - return () => window.removeEventListener("resize", checkMobile); - }, []); - useEffect(() => { const observer = new IntersectionObserver( (entries) => { @@ -162,6 +153,16 @@ export function FileList({ accountId, chatId }: FileListProps) { if (isMobile) { return (
+
{files.map((file, index) => ( onTypeChange(value as FileType)} > - + diff --git a/web/src/components/header.tsx b/web/src/components/header.tsx index 76c093c..84c9d11 100644 --- a/web/src/components/header.tsx +++ b/web/src/components/header.tsx @@ -30,23 +30,28 @@ import ChatSelect from "@/components/chat-select"; import Link from "next/link"; import TelegramIcon from "@/components/telegram-icon"; import AutoDownloadDialog from "@/components/auto-download-dialog"; +import useIsMobile from "@/hooks/use-is-mobile"; +import { useState } from "react"; +import {Button} from "@/components/ui/button"; export function Header() { const { isLoading, getAccounts, accountId, account, handleAccountChange } = useTelegramAccount(); const { connectionStatus, accountDownloadSpeed } = useWebsocket(); const accounts = getAccounts("active"); + const isMobile = useIsMobile(); + const [showMore, setShowMore] = useState(false); return ( -
-
+
+
-
+
- + {(!isMobile || showMore) && ( + <> + + + + + )} -
@@ -147,6 +157,15 @@ export function Header() {
+ +
diff --git a/web/src/hooks/use-is-mobile.ts b/web/src/hooks/use-is-mobile.ts new file mode 100644 index 0000000..dbc6c60 --- /dev/null +++ b/web/src/hooks/use-is-mobile.ts @@ -0,0 +1,19 @@ +import { useLayoutEffect, useState } from "react"; + +const useIsMobile = (): boolean => { + const [isMobile, setIsMobile] = useState(false); + + useLayoutEffect(() => { + const checkMobile = () => { + setIsMobile(window.innerWidth < 768); + }; + + checkMobile(); + window.addEventListener("resize", checkMobile); + return () => window.removeEventListener("resize", checkMobile); + }, []); + + return isMobile; +}; + +export default useIsMobile;