import * as React from "react"; import { Button, TextareaInput, buttonSizes, colors } from "@joincivil/elements"; import { StoryDetailsComments } from "./StoryFeedStyledComponents"; import { Mutation, MutationFunc, Query } from "react-apollo"; import { CivilComment } from "./CivilComment"; import { MoreComments } from "./MoreComments"; import { POST_COMMENT_MUTATION, COMMENT } from "./queries"; import { LoadingMessage } from "@joincivil/components"; import styled from "styled-components"; export interface PostCommentsProps { postId: string; comments: any; numComments: number; level: number; } const TopLevelReplySpan = styled.span` color: ${colors.accent.CIVIL_BLUE_FADED}; font-size: 12; margin-left: 0; `; const ReplySpan = styled.span` color: ${colors.accent.CIVIL_BLUE_FADED}; font-size: 8; margin-left: 0; `; export const PostComments: React.FunctionComponent = props => { const [commentText, setCommentText] = React.useState(""); const [myNewCommentIDs, setMyNewCommentIDs] = React.useState([]); const [showReply, setShowReply] = React.useState(props.level === 0); const edgesLength = props.comments && props.comments.edges ? props.comments.edges.length : 0; const remainingChildren = props.numComments - edgesLength; const endCursor = props.comments && props.comments.pageInfo ? props.comments.pageInfo.endCursor : ""; return ( <> {showReply && props.level === 0 && ( setShowReply(false)}>Hide Comment Form )} {showReply && props.level !== 0 && setShowReply(false)}>Hide Reply Form} {!showReply && props.level === 0 && ( setShowReply(true)}>Leave a Comment )} {!showReply && props.level !== 0 && setShowReply(true)}>Reply} {showReply && ( {(postCommentMutation: MutationFunc) => { return ( <> { setCommentText(value); }} maxLength={"500"} /> {props.level === 0 && ( )} ); }} )}
{myNewCommentIDs.map(postID => { return ( {({ loading, error, data }) => { if (loading) { return Loading Comment; } else if (error || !data || !data.postsGet) { console.error("error loading comment data. error:", error, "data:", data); return "Error loading comment."; } const comment = { post: data.postsGet }; return ; }} ); })} {props.comments && props.comments.edges && props.comments.edges.map(child => { return ; })}
); };