From bd218a7f56ee3c9836ad68766d75e02708d166b0 Mon Sep 17 00:00:00 2001 From: hanyd Date: Thu, 5 Sep 2024 17:11:23 +0800 Subject: [PATCH] Make refresh button spin for at least 1 circle --- public/shared.css | 6 ++++++ src/popup/VideoInfo/VideoInfo.tsx | 36 ++++++++++++++++++++++--------- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/public/shared.css b/public/shared.css index 79040ff1..f35653d6 100644 --- a/public/shared.css +++ b/public/shared.css @@ -233,3 +233,9 @@ .voteButton:hover { opacity: 0.8; } + +.anticon-spin::before, +.anticon-spin { + -webkit-animation: loadingCircle 0.5s infinite linear; + animation: loadingCircle 0.5s infinite linear; +} diff --git a/src/popup/VideoInfo/VideoInfo.tsx b/src/popup/VideoInfo/VideoInfo.tsx index 34ab5ba8..07cf8da5 100644 --- a/src/popup/VideoInfo/VideoInfo.tsx +++ b/src/popup/VideoInfo/VideoInfo.tsx @@ -1,4 +1,5 @@ import { ReloadOutlined } from "@ant-design/icons"; +import { Button } from "antd"; import { MessageInstance } from "antd/es/message/interface"; import * as React from "react"; import Config from "../../config"; @@ -7,6 +8,8 @@ import { SponsorTime } from "../../types"; import { exportTimes } from "../../utils/exporter"; import PopupSegment from "./PopupSegment"; +const BUTTON_REFRESH_DURATION = 500; + interface VideoInfoProps { messageApi: MessageInstance; sendTabMessage: (data: Message, callback?) => void; @@ -40,23 +43,39 @@ class VideoInfo extends React.Component { } private importTextRef = React.createRef(); + private stopLoadingTimeout; + private lastStartLoadingTime = performance.now(); startLoading() { this.setState({ loading: true }); + this.lastStartLoadingTime = performance.now(); + if (this.stopLoadingTimeout) { + clearTimeout(this.stopLoadingTimeout); + } } stopLoading() { - this.setState({ loading: false }); + const timeSinceStart = performance.now() - this.lastStartLoadingTime; + if (timeSinceStart < BUTTON_REFRESH_DURATION) { + this.stopLoadingTimeout = setTimeout(() => { + this.setState({ loading: false }); + this.stopLoadingTimeout = null; + }, BUTTON_REFRESH_DURATION - timeSinceStart); + } else { + this.setState({ loading: false }); + } } displayNoVideo() { // 无法找到视频,不是播放页面 - this.setState({ loading: false, videoFound: false }); + this.setState({ videoFound: false }); + this.stopLoading(); } displayVideoWithMessage(message: string = chrome.i18n.getMessage("sponsorFound")) { // 可以找到视频ID - this.setState({ loading: false, videoFound: true, loadedMessage: message }); + this.setState({ videoFound: true, loadedMessage: message }); + this.stopLoading(); } async refreshSegments() { @@ -143,13 +162,10 @@ class VideoInfo extends React.Component { {/* */}

{this.computeIndicatorText()}

- + + {/* */}
{this.SegmentList()}