Skip to content

Commit

Permalink
Move vote on port video record to content
Browse files Browse the repository at this point in the history
  • Loading branch information
hanydd committed Dec 10, 2024
1 parent 5453507 commit 3914b93
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
16 changes: 15 additions & 1 deletion src/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@ function setupCategoryPill() {

function setupDescriptionPill() {
if (!descriptionPill) {
descriptionPill = new DescriptionPortPill(getPortVideo, sponsorsLookup);
descriptionPill = new DescriptionPortPill(getPortVideo, portVideoVote, sponsorsLookup);
}
descriptionPill.setupDecription(getVideoID());
}
Expand All @@ -1261,6 +1261,20 @@ async function getPortVideo(videoId: VideoID, bypassCache = false) {
});
}

async function portVideoVote(UUID: string, bvID: VideoID, voteType: number) {
const response = await asyncRequestToServer("POST", "/api/votePort", {
UUID: UUID,
bvID: bvID,
userID: Config.config.userID,
type: voteType,
});
if (!response?.ok) {
throw response?.responseText ? response.responseText : "投票失败!";
}

await getPortVideo(this.bvID, true);
}

async function sponsorsLookup(keepOldSubmissions = true, ignoreServerCache = false, forceUpdatePreviewBar = false) {
if (lookupWaiting) return;
//there is still no video here
Expand Down
21 changes: 8 additions & 13 deletions src/render/DesciptionPortPill.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,21 @@ export class DescriptionPortPill {
portUUID: string;
hasDescription: boolean;
getPortVideo: (videoId: VideoID, bypassCache?: boolean) => void;
portVideoVote: (UUID: string, bvID: VideoID, voteType: number) => void;
sponsorsLookup: (keepOldSubmissions: boolean, ignoreServerCache: boolean, forceUpdatePreviewBar: boolean) => void;

inputContainer: HTMLElement;
buttonContainer: HTMLElement;
ref: React.RefObject<DescriptionPortPillComponent>;
root: Root;

constructor(getPortVideo: (videoId: VideoID, bypassCache?: boolean) => void, sponsorsLookup: () => void) {
constructor(
getPortVideo: (videoId: VideoID, bypassCache?: boolean) => void,
portVideoVote: (UUID: string, bvID: VideoID, voteType: number) => void,
sponsorsLookup: () => void
) {
this.getPortVideo = getPortVideo;
this.portVideoVote = portVideoVote;
this.sponsorsLookup = sponsorsLookup;
}

Expand Down Expand Up @@ -187,18 +193,7 @@ export class DescriptionPortPill {
return;
}

const response = await asyncRequestToServer("POST", "/api/votePort", {
UUID: this.portUUID,
bvID: this.bvID,
userID: Config.config.userID,
type: voteType,
});
if (!response?.ok) {
throw response?.responseText ? response.responseText : "投票失败!";
}

await this.getPortVideo(this.bvID, true);
this.ref.current.setState({ ytbVideoID: this.ytbID, previewYtbID: this.ytbID });
this.portVideoVote(this.portUUID, this.bvID, voteType);
}

private async updateSegments() {
Expand Down

0 comments on commit 3914b93

Please sign in to comment.