From d3ca25693977fb404d8d394ede7f9af266364a12 Mon Sep 17 00:00:00 2001 From: Law Wai Chun Date: Fri, 16 Aug 2024 00:14:39 +0800 Subject: [PATCH] Resume routine deployment --- .github/workflows/deploy.yml | 2 +- public/notice.json | 17 +++++++++ src/components/layout/NoticeCard.tsx | 53 ++++++++++++++++++++++------ 3 files changed, 60 insertions(+), 12 deletions(-) create mode 100644 public/notice.json diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 7e71cd50cef8..de1096d93997 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -5,7 +5,7 @@ name: Build & Deploy on: schedule: - - cron: "5 20 1 * *" + - cron: "5 20 * * *" workflow_dispatch: jobs: diff --git a/public/notice.json b/public/notice.json new file mode 100644 index 000000000000..c378b727505e --- /dev/null +++ b/public/notice.json @@ -0,0 +1,17 @@ +{ + "content": { + "zh": [ + "因資料一線通提供的 API 出現異常", + "hkbus.app 現以額外伺服器處理九巴資料", + "望請捐款支持" + ], + "en": [ + "Due to the API abnormality of data.gov.hk,", + "hkbus.app is now using extra server to handle KMB ETA.", + "We need your donations." + ] + }, + "url": "https://www.patreon.com/hkbus", + "enableLinkInIos": false, + "isShown": false +} \ No newline at end of file diff --git a/src/components/layout/NoticeCard.tsx b/src/components/layout/NoticeCard.tsx index 7a1518e96855..7cd7e86bb9c2 100644 --- a/src/components/layout/NoticeCard.tsx +++ b/src/components/layout/NoticeCard.tsx @@ -1,18 +1,49 @@ import { Box, Paper, SxProps, Theme, Typography } from "@mui/material"; -import ErrorIcon from "@mui/icons-material/Error"; +import WarnIcon from "@mui/icons-material/Warning"; +import useLanguage from "../../hooks/useTranslation"; +import { useCallback, useEffect, useState } from "react"; +import { iOSRNWebView } from "../../utils"; +import { Language } from "../../data"; + +interface NoticeCardState { + content: Record; + url: string; + enableLinkInIos: boolean; + isShown: boolean; +} const NoticeCard = () => { + const language = useLanguage(); + const [state, setState] = useState(null); + + useEffect(() => { + console.log("hihi"); + fetch("/notice.json") + .then((r) => r.json()) + .then((r) => setState(r)); + }, []); + + const handleClick = useCallback(() => { + if (state === null) return; + if (iOSRNWebView() && !state.enableLinkInIos) { + return; + } + window.open(state.url, "_target"); + }, [state]); + + if (state === null || !state.isShown) { + return null; + } + return ( - window.open("https://t.me/hkbusapp", "_target")} - > - + + - 因資料一線通提供的 API 出現異常 - hkbus.app 暫未能提供九巴到站預報 - 我們已向 1823 求助 + {state.content[language].map((v, idx) => ( + + {v} + + ))} ); @@ -27,6 +58,6 @@ const rootSx: SxProps = { py: 1, alignItems: "center", textAlign: "left", - gap: 1, + gap: 2, display: "flex", };