[WiP] createReaction debug

This commit is contained in:
ilya-bkv 2022-12-23 10:08:17 +03:00
parent 3411a23cf7
commit 8d4b06277b
3 changed files with 5 additions and 30 deletions

View File

@ -41,10 +41,10 @@ export default (props: Props) => {
event.preventDefault() event.preventDefault()
// await createReaction({ // await createReaction({
await apiClient.createReaction({ await apiClient.createReaction({
kind: 7,
replyTo: props.parent, replyTo: props.parent,
body: postMessageText(), body: postMessageText(),
shout: comment().shout.slug shout: comment().shout.slug,
kind: 7
}) })
} }
const formattedDate = createMemo(() => const formattedDate = createMemo(() =>
@ -168,9 +168,6 @@ export default (props: Props) => {
</Show> </Show>
</div> </div>
</Show> </Show>
<Show when={props.children}>
<ul>{props.children}</ul>
</Show>
</li> </li>
) )
} }

View File

@ -53,24 +53,6 @@ export const CommentsTree = (props: { shoutSlug: string }) => {
} }
onMount(async () => await loadMore()) onMount(async () => await loadMore())
const nestComments = (commentList) => {
const commentMap = {}
commentList.forEach((comment) => {
commentMap[comment.id] = comment
if (comment.replyTo !== null) {
const parent = commentMap[comment.replyTo] ?? []
;(parent.children = parent.children || []).push(comment)
}
})
return commentList.filter((comment) => {
return !comment.replyTo
})
}
createEffect(() => {
console.log('!!! re:', nestComments(reactions()))
})
return ( return (
<> <>
<Show when={!isCommentsLoading()} fallback={<Loading />}> <Show when={!isCommentsLoading()} fallback={<Loading />}>
@ -106,16 +88,13 @@ export const CommentsTree = (props: { shoutSlug: string }) => {
</div> </div>
<ul class={styles.comments}> <ul class={styles.comments}>
<For each={nestComments(reactions().reverse())}> <For each={reactions().reverse()}>
{(reaction: NestedReaction) => ( {(reaction: NestedReaction) => (
<Comment <Comment
comment={reaction} comment={reaction}
parent={reaction.id} parent={reaction.id}
level={getCommentLevel(reaction)} level={getCommentLevel(reaction)}
canEdit={reaction?.createdBy?.slug === session()?.user?.slug} canEdit={reaction?.createdBy?.slug === session()?.user?.slug}
children={(reaction.children || []).map((r) => {
return <Comment comment={r} parent={reaction.id} />
})}
/> />
)} )}
</For> </For>

View File

@ -230,9 +230,8 @@ export const apiClient = {
console.debug('createArticle response:', response) console.debug('createArticle response:', response)
return response.data.createShout return response.data.createShout
}, },
createReaction: async (input: ReactionInput) => { createReaction: async (reaction) => {
const response = await privateGraphQLClient.mutation(reactionCreate, { reaction: input }).toPromise() const response = await privateGraphQLClient.mutation(reactionCreate, { reaction: reaction }).toPromise()
console.log('!!! response:', response)
return response.data return response.data
}, },