diff --git a/src/components/Pages/HomePage.tsx b/src/components/Pages/HomePage.tsx index 392280bb..77896108 100644 --- a/src/components/Pages/HomePage.tsx +++ b/src/components/Pages/HomePage.tsx @@ -5,7 +5,7 @@ import { createSignal, onCleanup, onMount, Show } from 'solid-js' import { loadPublishedArticles, resetSortedArticles } from '../../stores/zine/articles' import { loadRandomTopics } from '../../stores/zine/topics' import { Loading } from '../Loading' - +import { InboxView } from '../Views/Inbox' export const HomePage = (props: PageProps) => { const [isLoaded, setIsLoaded] = createSignal(Boolean(props.homeArticles) && Boolean(props.randomTopics)) @@ -25,6 +25,7 @@ export const HomePage = (props: PageProps) => { return ( }> + diff --git a/src/components/Views/Inbox.tsx b/src/components/Views/Inbox.tsx index 47b67d91..f970c3e1 100644 --- a/src/components/Views/Inbox.tsx +++ b/src/components/Views/Inbox.tsx @@ -1,14 +1,93 @@ +import { For, createSignal, Show, onMount } from 'solid-js' import type { Author } from '../../graphql/types.gen' import { AuthorCard } from '../Author/Card' import { Icon } from '../Nav/Icon' +import { Loading } from '../Loading' import '../../styles/Inbox.scss' +// Для моков +import { createClient } from '@urql/core' + +const OWNER_ID = '501' +const client = createClient({ + url: 'https://graphqlzero.almansi.me/api' +}) // interface InboxProps { // chats?: Chat[] // messages?: Message[] // } +const [messages, setMessages] = createSignal([]) +const [postMessageText, setPostMessageText] = createSignal('') +const [loading, setLoading] = createSignal(false) + +const messageQuery = ` +query Comments ($options: PageQueryOptions) { + comments(options: $options) { + data { + id + body + email + } + } +} +` + +const newMessageQuery = ` +mutation postComment($messageBody: String!) { + createComment( + input: { body: $messageBody, email: "test@test.com", name: "User" } + ) { + id + body + name + email + } +} +` +const fetchMessages = async (query) => { + const response = await client + .query(query, { + options: { slice: { start: 0, end: 3 } } + }) + .toPromise() + if (response.error) console.debug('getMessages', response.error) + setMessages(response.data.comments.data) +} + +const postMessage = async (msg: string) => { + const response = await client.mutation(newMessageQuery, { messageBody: msg }).toPromise() + return response.data.createComment +} + +let chatWindow +onMount(() => { + setLoading(true) + fetchMessages(messageQuery) + .then(() => { + setLoading(false) + chatWindow.scrollTop = chatWindow.scrollHeight + }) + .catch(() => setLoading(false)) +}) export const InboxView = () => { + const handleSubmit = async () => { + postMessage(postMessageText()) + .then((result) => { + setMessages((prev) => [...prev, result]) + }) + .then(() => { + setPostMessageText('') + chatWindow.scrollTop = chatWindow.scrollHeight + console.log('!!! msg:', messages()) + }) + } + + const handleChangeMessage = (event) => { + setPostMessageText(event.target.value) + console.log('!!! asd:', postMessageText().trim().length) + } + // TODO: get user session return (
@@ -37,13 +116,6 @@ export const InboxView = () => {
    -
  • - -
    12:15
    -
    - Lorem ipsum dolor sit amet, consectetur adipisicing elit. -
    -
  • 19:48
    @@ -64,59 +136,50 @@ export const InboxView = () => {
-
-
-
- Круто, беру в оборот! -
- +
+ + + + + {(comment: { body: string; id: string; email: string }) => ( +
+
+ {comment.body} +
+ + {comment.email} id: {comment.id} +
+ +
- -
-
+ )} + -
-
- Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aut beatae earum iste itaque - libero perspiciatis possimus quod! Accusamus, aliquam amet consequuntur debitis dolorum - esse laudantium magni omnis rerum voluptatem voluptates! -
- - Отредактировано -
- -
-
- -
- -
- -
-
- Нужна грамотная инфраструктура для сообщений, если ожидается нагрузка - надо опираться на - это. Но в целом это несложно сделать. -
- -
- -
-
+ {/*
*/} + {/* */} + {/*
*/}
-
- -