From df3df9a04552f117322f66bd4cb79606535889ea Mon Sep 17 00:00:00 2001 From: Der_Googler <54764558+DerGoogler@users.noreply.github.com> Date: Thu, 29 Aug 2024 14:11:02 +0200 Subject: [PATCH] small improvements --- src/activitys/MainActivity.tsx | 45 ++++++++++--------- src/activitys/ModuleViewActivity/index.tsx | 25 +++++------ .../ModuleViewActivity/tabs/VersionsTab.tsx | 1 - src/components/module/ExploreModule.tsx | 8 ++++ src/components/module/UpdateModule.tsx | 1 - src/hooks/useHover.ts | 23 ++++++++++ 6 files changed, 66 insertions(+), 37 deletions(-) create mode 100644 src/hooks/useHover.ts diff --git a/src/activitys/MainActivity.tsx b/src/activitys/MainActivity.tsx index e8f7e20a..23568619 100644 --- a/src/activitys/MainActivity.tsx +++ b/src/activitys/MainActivity.tsx @@ -1,34 +1,33 @@ -import { CloseRounded } from "@mui/icons-material"; -import { useState } from "react"; -import { RouterUtil } from "@Util/RouterUtil"; -import { IntentPusher } from "../hooks/useActivity"; +import { Code } from "@Components/dapi/Code"; +import { Pre } from "@Components/dapi/Pre"; +import { ErrorBoundary } from "@Components/ErrorBoundary"; +import Icon from "@Components/Icon"; +import { Page } from "@Components/onsenui/Page"; +import { RouterNavigator } from "@Components/onsenui/RouterNavigator"; +import { Splitter } from "@Components/onsenui/Splitter"; +import { Toolbar } from "@Components/onsenui/Toolbar"; import { useSettings } from "@Hooks/useSettings"; -import React from "react"; +import { useTheme } from "@Hooks/useTheme"; +import { CloseRounded } from "@mui/icons-material"; +import CodeRoundedIcon from "@mui/icons-material/CodeRounded"; import { Button, Typography } from "@mui/material"; import { os } from "@Native/Os"; import { Shell } from "@Native/Shell"; +import { RouterUtil } from "@Util/RouterUtil"; +import eruda from "eruda"; +import React, { useState } from "react"; +import { IntentPusher } from "../hooks/useActivity"; +import { DrawerFragment } from "./fragments/DrawerFragment"; import MainApplication from "./MainApplication"; import NoRootActivity from "./NoRootActivity"; -import { ErrorBoundary } from "@Components/ErrorBoundary"; -import Icon from "@Components/Icon"; import SettingsActivity from "./SettingsActivity"; -import { Splitter } from "@Components/onsenui/Splitter"; -import { RouterNavigator } from "@Components/onsenui/RouterNavigator"; -import { DrawerFragment } from "./fragments/DrawerFragment"; -import { Toolbar } from "@Components/onsenui/Toolbar"; -import CodeRoundedIcon from "@mui/icons-material/CodeRounded"; -import { Page } from "@Components/onsenui/Page"; -import eruda from "eruda"; -import { useTheme } from "@Hooks/useTheme"; -import { Pre } from "@Components/dapi/Pre"; -import { Code } from "@Components/dapi/Code"; - -import pkg from "@Package"; -import UnverifiedHostActivity from "./UnverifiedHostActivity"; +import useMediaQuery from "@mui/material/useMediaQuery"; import { useModFS } from "@Hooks/useModFS"; +import { useStrings } from "@Hooks/useStrings"; import { SuFile } from "@Native/SuFile"; +import pkg from "@Package"; import { LogcatActivity } from "./LogcatActivity"; -import { useStrings } from "@Hooks/useStrings"; +import UnverifiedHostActivity from "./UnverifiedHostActivity"; const getLocation = () => { if (window.location !== window.parent.location) { @@ -274,6 +273,8 @@ const MainActivity = (): JSX.Element => { ); }; + const matches = useMediaQuery("(max-width: 767px)"); + return ( { @@ -287,7 +288,7 @@ const MainActivity = (): JSX.Element => { { const [moduleFileSize, moduleFileSizeByteText] = useFormatBytes(size); const search = React.useMemo(() => new URLSearchParams(window.location.search), [window.location.search]); - const handleOpenModuleSearch = useOpenModuleSearch(modules); + + useDocumentTitle(`${name} — MMRL`, { preserveTitleOnUnmount: false }); React.useEffect(() => { search.set("module", id); diff --git a/src/activitys/ModuleViewActivity/tabs/VersionsTab.tsx b/src/activitys/ModuleViewActivity/tabs/VersionsTab.tsx index 90e60772..d907a770 100644 --- a/src/activitys/ModuleViewActivity/tabs/VersionsTab.tsx +++ b/src/activitys/ModuleViewActivity/tabs/VersionsTab.tsx @@ -1,5 +1,4 @@ import FetchTextActivity from "@Activitys/FetchTextActivity"; -import InstallTerminalActivity from "@Activitys/InstallTerminalActivity"; import InstallTerminalV2Activity from "@Activitys/InstallTerminalV2Activity"; import { useActivity } from "@Hooks/useActivity"; import { useDownloadModule } from "@Hooks/useDownloadModule"; diff --git a/src/components/module/ExploreModule.tsx b/src/components/module/ExploreModule.tsx index 0cbab747..5a7f2721 100644 --- a/src/components/module/ExploreModule.tsx +++ b/src/components/module/ExploreModule.tsx @@ -16,6 +16,7 @@ import { useModuleInfo } from "@Hooks/useModuleInfo"; import { Verified, Tag, PersonOutline, CalendarMonth, Source } from "@mui/icons-material"; import { useBlacklist } from "@Hooks/useBlacklist"; import Box from "@mui/material/Box"; +import { useHover } from "@Hooks/useHover"; interface Props { module: Module; @@ -43,14 +44,21 @@ const ExploreModule = React.memo((props) => { extra: props.module, }); }; + + const cardRef = React.useRef(null); + const isHover = useHover(cardRef); + return ( diff --git a/src/components/module/UpdateModule.tsx b/src/components/module/UpdateModule.tsx index e2925938..214894d6 100644 --- a/src/components/module/UpdateModule.tsx +++ b/src/components/module/UpdateModule.tsx @@ -16,7 +16,6 @@ import { useStrings } from "@Hooks/useStrings"; import { useActivity } from "@Hooks/useActivity"; import { useRepos } from "@Hooks/useRepos"; -import InstallTerminalActivity from "@Activitys/InstallTerminalActivity"; import FetchTextActivity from "@Activitys/FetchTextActivity"; import { link } from "googlers-tools"; diff --git a/src/hooks/useHover.ts b/src/hooks/useHover.ts new file mode 100644 index 00000000..3fedb893 --- /dev/null +++ b/src/hooks/useHover.ts @@ -0,0 +1,23 @@ +import { useState } from "react"; + +import type { RefObject } from "react"; + +import { useEventListener } from "usehooks-ts"; + +export function useHover(elementRef: RefObject): boolean { + const [value, setValue] = useState(false); + + const handleEnter = () => { + setValue(true); + }; + const handleLeave = () => { + setValue(false); + }; + + useEventListener("touchstart", handleEnter, elementRef); + useEventListener("touchend", handleLeave, elementRef); + useEventListener("mouseenter", handleEnter, elementRef); + useEventListener("mouseleave", handleLeave, elementRef); + + return value; +}