From 0a6c1c6b42b62650b5740f28345532a73a6b0210 Mon Sep 17 00:00:00 2001 From: zerosoul Date: Thu, 12 May 2022 14:18:36 +0800 Subject: [PATCH] refactor: pwa prompt modal --- src/common/component/Manifest/Prompt.js | 43 ++++++++++++++-------- src/common/component/Manifest/index.js | 4 ++ src/common/component/Manifest/usePrompt.js | 16 ++++++++ src/routes/index.js | 2 - 4 files changed, 47 insertions(+), 18 deletions(-) create mode 100644 src/common/component/Manifest/usePrompt.js diff --git a/src/common/component/Manifest/Prompt.js b/src/common/component/Manifest/Prompt.js index 270f7bc3..99f6d6ed 100644 --- a/src/common/component/Manifest/Prompt.js +++ b/src/common/component/Manifest/Prompt.js @@ -1,13 +1,14 @@ // import React from "react"; import styled from "styled-components"; import Modal from "../Modal"; +import IconClose from "../../../assets/icons/close.svg"; import Button from "../../component/styled/Button"; - const Styled = styled.div` + position: relative; margin-top: 15px; pointer-events: all; - width: 300px; - padding: 16px 32px; + width: 406px; + padding: 16px; border-radius: 6px; background: #fff; box-shadow: 0px 25px 50px rgba(31, 41, 55, 0.25); @@ -15,42 +16,52 @@ const Styled = styled.div` flex-direction: column; gap: 12px; .tip { - line-height: 1.4; display: flex; flex-direction: column; - gap: 5px; - color: #333; + gap: 16px; + color: #344054; .title { - font-size: 18px; - font-weight: bold; + font-weight: 600; + font-size: 16px; + line-height: 24px; } .desc { - font-size: 12px; - color: #666; + font-weight: 400; + font-size: 14px; + line-height: 20px; } } .btns { width: 100%; display: flex; justify-content: flex-end; - gap: 12px; + gap: 16px; + } + .close { + cursor: pointer; + position: absolute; + top: 16px; + right: 16px; } `; export default function Prompt({ handleInstall, closePrompt }) { return ( +
-

Add this Web APP

-

Add to your PC and open like native APP

+

Install web app on desktop?

+

+ Put it on your desktop for quick access to apps. +

+ -
diff --git a/src/common/component/Manifest/index.js b/src/common/component/Manifest/index.js index 6d47b304..6c7743ec 100644 --- a/src/common/component/Manifest/index.js +++ b/src/common/component/Manifest/index.js @@ -2,7 +2,10 @@ import { useEffect, useState, useRef } from "react"; // import { useGetServerQuery } from "../../../app/services/server"; // import manifest from "./manifest.json"; import Prompt from "./Prompt"; +import usePrompt from "./usePrompt"; + export default function Manifest() { + const { setCanneled } = usePrompt(); const deferredPromptRef = useRef(null); const [popup, setPopup] = useState(false); // const { data, isSuccess } = useGetServerQuery(); @@ -56,6 +59,7 @@ export default function Manifest() { deferredPromptRef.current = null; }; const handleClose = async () => { + setCanneled(); setPopup(false); }; if (!popup) return null; diff --git a/src/common/component/Manifest/usePrompt.js b/src/common/component/Manifest/usePrompt.js new file mode 100644 index 00000000..78458834 --- /dev/null +++ b/src/common/component/Manifest/usePrompt.js @@ -0,0 +1,16 @@ +// import React from "react"; +const Key = `RUSTCHAT_PWA_PROMPT`; +export default function usePrompt() { + const resetPrompt = () => { + localStorage.removeItem(Key); + }; + const setPrompt = () => { + localStorage.setItem(Key, true); + }; + + return { + setCanneled: setPrompt, + prompted: !!localStorage.getItem(Key), + resetPrompt, + }; +} diff --git a/src/routes/index.js b/src/routes/index.js index b32164de..d98fbe32 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -23,7 +23,6 @@ import SettingPage from "./setting"; import SettingChannelPage from "./settingChannel"; import toast from "react-hot-toast"; import ResourceManagement from "./resources"; -import Manifest from "../common/component/Manifest"; const PageRoutes = () => { const { @@ -129,7 +128,6 @@ export default function ReduxRoutes() { // }; return ( -