import * as React from "react"; import Config from "../config"; import { Category, SegmentUUID, SponsorTime } from "../types"; import ThumbsUpSvg from "../svg-icons/thumbs_up_svg"; import ThumbsDownSvg from "../svg-icons/thumbs_down_svg"; import { downvoteButtonColor, SkipNoticeAction } from "../utils/noticeUtils"; import { VoteResponse } from "../messageTypes"; import { AnimationUtils } from "../utils/animationUtils"; import { GenericUtils } from "../utils/genericUtils"; import { Tooltip } from "../render/Tooltip"; export interface ChapterVoteProps { vote: (type: number, UUID: SegmentUUID, category?: Category) => Promise; } export interface ChapterVoteState { segment?: SponsorTime; show: boolean; } class ChapterVoteComponent extends React.Component { tooltip?: Tooltip; constructor(props: ChapterVoteProps) { super(props); this.state = { segment: null, show: false }; } render(): React.ReactElement { if (this.tooltip && !this.state.show) { this.tooltip.close(); this.tooltip = null; } return ( <> {/* Upvote Button */} {/* Downvote Button */} ); } private async vote(event: React.MouseEvent, type: number, element?: HTMLElement): Promise { event.stopPropagation(); if (this.state.segment) { const stopAnimation = AnimationUtils.applyLoadingAnimation(element ?? event.currentTarget as HTMLElement, 0.3); const response = await this.props.vote(type, this.state.segment.UUID); await stopAnimation(); if (response.successType == 1 || (response.successType == -1 && response.statusCode == 429)) { this.setState({ show: type === 1 }); } else if (response.statusCode !== 403) { alert(GenericUtils.getErrorMessage(response.statusCode, response.responseText)); } } } } export default ChapterVoteComponent;