Skip to content

Commit

Permalink
fix loading state when submitting port video
Browse files Browse the repository at this point in the history
  • Loading branch information
hanydd committed Dec 16, 2024
1 parent 371078d commit 20bd986
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/components/DescriptionPortPillComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { LoadingOutlined } from "@ant-design/icons";
import { ConfigProvider, Spin } from "antd";
import * as React from "react";
import { showMessage } from "../render/MessageNotice";
Expand Down Expand Up @@ -41,7 +42,7 @@ export class DescriptionPortPillComponent extends React.Component<DescriptionPor
render(): React.ReactElement {
return (
<ConfigProvider>
<Spin delay={100} spinning={this.state.loading}>
<Spin indicator={<LoadingOutlined spin />} delay={100} spinning={this.state.loading}>
<div hidden={!this.state.show} id="bsbDescriptionPortVideoPill">
{this.hasYtbVideo() && (
<>
Expand Down
2 changes: 1 addition & 1 deletion src/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ function messageListener(
);
break;
case "submitPortVideo":
submitPortVideo(request.ytbID).then((response) => sendResponse(response));
submitPortVideo(request.ytbID);
break;
}

Expand Down
35 changes: 20 additions & 15 deletions src/popup/PortVideoSection.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { LoadingOutlined } from "@ant-design/icons";
import { Spin } from "antd";
import { MessageInstance } from "antd/es/message/interface";
import * as React from "react";
import { Message } from "../messageTypes";
import { parseYoutubeID } from "../utils/parseVideoID";
import { PortVideo } from "../types";
import { parseYoutubeID } from "../utils/parseVideoID";

interface PortVideoProps {
messageApi: MessageInstance;
Expand All @@ -21,7 +23,7 @@ export class PortVideoSection extends React.Component<PortVideoProps, PortVideoS
super(props);
this.state = {
show: false,
loading: false,
loading: true,
portVideo: null,
};
}
Expand All @@ -37,7 +39,7 @@ export class PortVideoSection extends React.Component<PortVideoProps, PortVideoS
}

private hasPortVideo(): boolean {
return !!this.state.portVideo;
return !!this.state.portVideo?.UUID;
}

private async submitPortVideo(): Promise<void> {
Expand All @@ -46,27 +48,30 @@ export class PortVideoSection extends React.Component<PortVideoProps, PortVideoS
return;
}
const ytbID = parseYoutubeID(YtbInput);
// this.setState({ loading: true });
if (!ytbID) {
this.props.messageApi.warning("YouTube视频ID有误");
return;
}
console.log("portvideo submitPortVideo", ytbID, this.state);
this.setState({ loading: true });

try {
const newPortVideo = await this.props.sendTabMessageAsync({ message: "submitPortVideo", ytbID: ytbID });
if (newPortVideo) {
this.setState({ portVideo: newPortVideo as PortVideo });
}
await this.props.sendTabMessageAsync({ message: "submitPortVideo", ytbID: ytbID });
} catch (e) {
this.props.messageApi.error(e.getMessage());
}
}

render() {
return (
<>
<div>
{this.state.show && (
<div>
<Spin indicator={<LoadingOutlined spin />} delay={100} spinning={this.state.loading}>
{this.hasPortVideo() ? (
<div>
<div>{this.state.portVideo.ytbID}</div>
</div>
<>
<span>{chrome.i18n.getMessage("hasbindedPortVideo")}</span>
<span>{this.state.portVideo.ytbID}</span>
</>
) : (
<>
<input
Expand All @@ -79,9 +84,9 @@ export class PortVideoSection extends React.Component<PortVideoProps, PortVideoS
</button>
</>
)}
</div>
</Spin>
)}
</>
</div>
);
}
}

0 comments on commit 20bd986

Please sign in to comment.