import { AppearingComponent } from "./Appearing"; import { Avatar, Button, Col, Drawer, Form, Row } from "antd"; import { Callback, NLView } from "../types"; import { ContentImage } from "./Image"; import { ContentLayout } from "./ContentLayout"; import { EyeOpen } from "./Icons/EyeOpen"; import { LargeArrowBack } from "./Icons/LargeArrowBack"; import { Link } from "react-router-dom"; import { ReactElement, useEffect, useRef } from "react"; import { SelectMood, SelectMoodForm } from "./SelectMood"; import { Share } from "./Share"; import { SimplifiedTag, useVotingStreamMood } from "../Pages/Post/Post"; import { SmallFolder } from "./Icons/SmallFolder"; import { Tags } from "../Pages/Post/components/Tags"; import { useActions, useAppState, useEffects } from "../overmind"; import { useCachedUser } from "../hooks/useCached"; import PostReportModal from "../Pages/Post/components/PostModal"; import Title from "../Pages/Explore/Title"; import useMediaQuery from "../hooks/useMediaQuery"; const preventEvent = (e: React.SyntheticEvent) => { e.stopPropagation(); e.preventDefault(); e.nativeEvent.stopImmediatePropagation(); return false; }; export const Vote: NLView<{ // useVotingStream: typeof useVotingStreamMood, onDoneVoting: (val: number) => void; onLongDoneVoting?: Callback; info: ReactElement; votingEnabled?: boolean; setVisible?: React.Dispatch>; visible?: boolean; addToMoods?: Callback; containerDeeplike?: React.MutableRefObject; isEyeOpenedResponzive?: boolean; visionTags?: SimplifiedTag[]; nonVisionTags?: SimplifiedTag[]; setHilightTag?: React.Dispatch>; setIsEyeOpenedResponzive?: React.Dispatch>; }> = ({ // useVotingStream, onDoneVoting, onLongDoneVoting, children, info, votingEnabled, setVisible, visible, addToMoods, containerDeeplike, isEyeOpenedResponzive, visionTags, nonVisionTags, setHilightTag, setIsEyeOpenedResponzive, }) => { const divMessage = useRef(); const divAppearingMessage = useRef(); const effects = useEffects(); const actions = useActions(); const state = useAppState(); const isResponzive = useMediaQuery("(max-width: 1024px)"); const nextInStream = useVotingStreamMood(); const { currPost } = nextInStream; const author = useCachedUser({ id: currPost ? currPost?.author?.id : "" }); useEffect(() => { effects.ux.message.config({ maxCount: 2, duration: 1, getContainer: () => divMessage?.current, }); return effects.ux.message.config({ getContainer: undefined, }); }, []); useEffect(() => { if (votingEnabled) actions.flows.rating.deepLikeInit(); actions.ux.setLayout({ headerShown: false }); return () => { actions.ux.setLayout({ headerShown: true }); }; }, []); useEffect(() => { if (votingEnabled) actions.flows.rating.deepLikeInit(); }, [state.routing.location]); useEffect(() => { const r = state.flows.rating; if (!r.isRating && !r.rated) return; if (r.rated && !r.value) return; if ((!r.isRating && r.rated) || r.value >= 100) onDoneVoting(r.value); }, [state.flows.rating.isRating, state.flows.rating.value]); const touchClickVoteStart = (e: React.SyntheticEvent) => { // preventEvent(e); actions.flows.rating.deepLikeStart({ event: e.nativeEvent }); }; const touchClickVoteStop = (e: React.SyntheticEvent) => { preventEvent(e); actions.flows.rating.deepLikeStop(); }; return (
{state.flows.rating.value === 100 && (
Tap spacebar to continue
)} {state.flows.rating.isRating && !state.flows.rating.rated && !state.flows.rating.value && (
Hold spacebar to vote
)}
} info={ <> {isResponzive && visionTags && nonVisionTags && setHilightTag ? (
{/* infobox */} {isEyeOpenedResponzive && ( { setHilightTag([]); setIsEyeOpenedResponzive!(false); setVisible!(true); }} onMouseOver={() => setHilightTag(visionTags)} onMouseOut={() => setHilightTag([])} > { setIsEyeOpenedResponzive!(false); setVisible!(true); }} > )} {/* infobox */}
{ state.flows.rating.value === 100 && !isEyeOpenedResponzive && setVisible!((p) => !p); }} > <> } className="u-margin-right-small" /> {author?.username &&

{author.username}

}
) : ( info )}
{isResponzive ? info : null}
<Form.Item name="moods" style={{ margin: 0 }}> <SelectMood deeplikeActions /> </Form.Item> </Form> </Drawer> </div> </> } > <div className="flex-center nl-fullsize-image app-main-full-height-only nl-post-img-wrapper" onMouseDown={touchClickVoteStart} onMouseUp={touchClickVoteStop} onTouchStart={touchClickVoteStart} onTouchEnd={touchClickVoteStop} onContextMenu={preventEvent} > {children} </div> {/* green line */} {true || state.flows.rating.isRating ? ( <div className="nl-rating-bar-wrapper"> <div className="nl-rating-bar" style={{ opacity: [0, 100].includes(state.flows.rating.value) ? 0 : 100, width: `${state.flows.rating.value || 0}vw`, }} ></div> </div> ) : ( "" )} </ContentLayout> ); };