From 9c7ad681e946535ea55ba9fb3e2fe6204ec1f2d4 Mon Sep 17 00:00:00 2001 From: Junhao Liao Date: Thu, 3 Oct 2024 10:10:54 +0800 Subject: [PATCH 01/38] Add load state for UI components. --- .../components/DropFileContainer/index.css | 5 +++ .../components/DropFileContainer/index.tsx | 19 ++++++++--- .../components/MenuBar/ExportLogsButton.tsx | 8 ++--- .../src/components/MenuBar/NavigationBar.tsx | 34 ++++++++++++------- .../src/components/MenuBar/PageNumInput.tsx | 4 ++- .../src/components/MenuBar/index.tsx | 23 +++++++++++-- .../src/components/StatusBar/index.tsx | 4 ++- .../src/contexts/StateContextProvider.tsx | 15 ++++++++ new-log-viewer/src/typings/worker.ts | 7 ++++ 9 files changed, 92 insertions(+), 27 deletions(-) diff --git a/new-log-viewer/src/components/DropFileContainer/index.css b/new-log-viewer/src/components/DropFileContainer/index.css index 6d6ca94b..2199af1f 100644 --- a/new-log-viewer/src/components/DropFileContainer/index.css +++ b/new-log-viewer/src/components/DropFileContainer/index.css @@ -22,6 +22,11 @@ background-color: rgb(2 88 168 / 20%); } +.hover-mask-loading { + cursor: progress; + background-color: rgba(168, 2, 2, 0.2); +} + .hover-message { z-index: var(--ylv-drop-file-container-hover-message-z-index); diff --git a/new-log-viewer/src/components/DropFileContainer/index.tsx b/new-log-viewer/src/components/DropFileContainer/index.tsx index a355c9e8..06c8c398 100644 --- a/new-log-viewer/src/components/DropFileContainer/index.tsx +++ b/new-log-viewer/src/components/DropFileContainer/index.tsx @@ -4,7 +4,10 @@ import React, { } from "react"; import {StateContext} from "../../contexts/StateContextProvider"; -import {CURSOR_CODE} from "../../typings/worker"; +import { + CURSOR_CODE, + LOAD_STATE, +} from "../../typings/worker"; import "./index.css"; @@ -21,7 +24,7 @@ interface DropFileContextProviderProps { * @return */ const DropFileContainer = ({children}: DropFileContextProviderProps) => { - const {loadFile} = useContext(StateContext); + const {loadFile, loadState} = useContext(StateContext); const [isFileHovering, setIsFileHovering] = useState(false); const handleDrag = (ev: React.DragEvent) => { @@ -52,7 +55,9 @@ const DropFileContainer = ({children}: DropFileContextProviderProps) => { ev.stopPropagation(); setIsFileHovering(false); - + if (loadState === LOAD_STATE.LOADING) { + return; + } const [file] = ev.dataTransfer.files; if ("undefined" === typeof file) { console.warn("No file dropped."); @@ -77,14 +82,18 @@ const DropFileContainer = ({children}: DropFileContextProviderProps) => { {children} {isFileHovering && (
- Drop file to view + {loadState === LOAD_STATE.LOADING ? + "Loading in progress" : + "Drop file to view"}
)} diff --git a/new-log-viewer/src/components/MenuBar/ExportLogsButton.tsx b/new-log-viewer/src/components/MenuBar/ExportLogsButton.tsx index 5d998e8d..60bb3833 100644 --- a/new-log-viewer/src/components/MenuBar/ExportLogsButton.tsx +++ b/new-log-viewer/src/components/MenuBar/ExportLogsButton.tsx @@ -12,6 +12,7 @@ import { EXPORT_LOG_PROGRESS_VALUE_MAX, EXPORT_LOG_PROGRESS_VALUE_MIN, } from "../../services/LogExportManager"; +import {LOAD_STATE} from "../../typings/worker"; import SmallIconButton from "./SmallIconButton"; @@ -21,16 +22,13 @@ import SmallIconButton from "./SmallIconButton"; * @return */ const ExportLogsButton = () => { - const {exportLogs, exportProgress, fileName} = useContext(StateContext); + const {exportLogs, exportProgress, loadState} = useContext(StateContext); return ( diff --git a/new-log-viewer/src/components/MenuBar/NavigationBar.tsx b/new-log-viewer/src/components/MenuBar/NavigationBar.tsx index da050839..10671c20 100644 --- a/new-log-viewer/src/components/MenuBar/NavigationBar.tsx +++ b/new-log-viewer/src/components/MenuBar/NavigationBar.tsx @@ -1,14 +1,19 @@ import React, {useContext} from "react"; +import { + ButtonGroup, + IconButton, +} from "@mui/joy"; + import NavigateBefore from "@mui/icons-material/NavigateBefore"; import NavigateNext from "@mui/icons-material/NavigateNext"; import SkipNext from "@mui/icons-material/SkipNext"; import SkipPrevious from "@mui/icons-material/SkipPrevious"; import {StateContext} from "../../contexts/StateContextProvider"; +import {LOAD_STATE} from "../../typings/worker"; import {ACTION_NAME} from "../../utils/actions"; import PageNumInput from "./PageNumInput"; -import SmallIconButton from "./SmallIconButton"; /** @@ -17,7 +22,7 @@ import SmallIconButton from "./SmallIconButton"; * @return */ const NavigationBar = () => { - const {loadPageByAction} = useContext(StateContext); + const {loadState, loadPageByAction} = useContext(StateContext); const handleNavButtonClick = (event: React.MouseEvent) => { const {actionName} = event.currentTarget.dataset; @@ -34,35 +39,40 @@ const NavigationBar = () => { }; return ( - <> - + - - + - + - - - + - - + + ); }; diff --git a/new-log-viewer/src/components/MenuBar/PageNumInput.tsx b/new-log-viewer/src/components/MenuBar/PageNumInput.tsx index cf37059a..f4f37194 100644 --- a/new-log-viewer/src/components/MenuBar/PageNumInput.tsx +++ b/new-log-viewer/src/components/MenuBar/PageNumInput.tsx @@ -9,6 +9,7 @@ import {Typography} from "@mui/joy"; import Input from "@mui/joy/Input"; import {StateContext} from "../../contexts/StateContextProvider"; +import {LOAD_STATE} from "../../typings/worker"; import {ACTION_NAME} from "../../utils/actions"; import "./PageNumInput.css"; @@ -23,7 +24,7 @@ const PAGE_NUM_INPUT_FIT_EXTRA_WIDTH = 2; * @return */ const PageNumInput = () => { - const {loadPageByAction, numPages, pageNum} = useContext(StateContext); + const {loadState, loadPageByAction, numPages, pageNum} = useContext(StateContext); const [isEditing, setIsEditing] = useState(false); const inputRef = useRef(null); @@ -79,6 +80,7 @@ const PageNumInput = () => { > { - const {fileName, loadFile} = useContext(StateContext); + const {fileName, loadState, loadFile} = useContext(StateContext); const [isSettingsModalOpen, setIsSettingsModalOpen] = useState(false); @@ -68,17 +72,30 @@ const MenuBar = () => { - + + {loadState === LOAD_STATE.LOADING && + } diff --git a/new-log-viewer/src/components/StatusBar/index.tsx b/new-log-viewer/src/components/StatusBar/index.tsx index 1d8598f2..9e9acede 100644 --- a/new-log-viewer/src/components/StatusBar/index.tsx +++ b/new-log-viewer/src/components/StatusBar/index.tsx @@ -9,6 +9,7 @@ import { copyPermalinkToClipboard, UrlContext, } from "../../contexts/UrlContextProvider"; +import {LOAD_STATE} from "../../typings/worker"; import "./index.css"; @@ -26,7 +27,7 @@ const handleCopyLinkButtonClick = () => { * @return */ const StatusBar = () => { - const {numEvents} = useContext(StateContext); + const {loadState, numEvents} = useContext(StateContext); const {logEventNum} = useContext(UrlContext); return ( @@ -38,6 +39,7 @@ const StatusBar = () => { Status message