From ac3f29defc6666114d27ba7105b3f3a80e81bc3d Mon Sep 17 00:00:00 2001 From: bniwredyc Date: Tue, 11 Apr 2023 15:57:48 +0200 Subject: [PATCH] create shout -> edit --- codegen.yml | 4 +- src/components/App.tsx | 4 +- src/components/Article/CommentsTree.tsx | 2 - src/components/Article/FullArticle.tsx | 6 +- src/components/Editor/Editor.tsx | 11 +-- .../EditorBubbleMenu/EditorBubbleMenu.tsx | 6 +- src/components/Nav/HeaderAuth.tsx | 2 +- src/components/Topic/Full.tsx | 2 +- .../{Create.module.scss => Edit.module.scss} | 4 +- src/components/Views/{Create.tsx => Edit.tsx} | 77 +++++++++++-------- src/graphql/mutation/article-create.ts | 12 --- src/graphql/mutation/draft-create.ts | 28 ------- src/graphql/mutation/draft-destroy.ts | 9 --- src/graphql/mutation/draft-to-shout.ts | 28 ------- src/graphql/mutation/draft-update.ts | 28 ------- src/graphql/query/my-drafts.ts | 17 ---- src/graphql/types.gen.ts | 62 ++------------- src/pages/create.page.tsx | 21 +++-- ...tings.page.route.ts => edit.page.route.ts} | 2 +- src/pages/edit.page.tsx | 40 ++++++++++ src/pages/editSettings.page.route.ts | 4 + src/stores/editor.ts | 33 -------- src/stores/router.ts | 3 +- 23 files changed, 126 insertions(+), 279 deletions(-) rename src/components/Views/{Create.module.scss => Edit.module.scss} (96%) rename src/components/Views/{Create.tsx => Edit.tsx} (80%) delete mode 100644 src/graphql/mutation/draft-create.ts delete mode 100644 src/graphql/mutation/draft-destroy.ts delete mode 100644 src/graphql/mutation/draft-to-shout.ts delete mode 100644 src/graphql/mutation/draft-update.ts delete mode 100644 src/graphql/query/my-drafts.ts rename src/pages/{createSettings.page.route.ts => edit.page.route.ts} (65%) create mode 100644 src/pages/edit.page.tsx create mode 100644 src/pages/editSettings.page.route.ts delete mode 100644 src/stores/editor.ts diff --git a/codegen.yml b/codegen.yml index da015e44..2d1b69b7 100644 --- a/codegen.yml +++ b/codegen.yml @@ -1,6 +1,6 @@ overwrite: true -#schema: 'http://localhost:8080' -schema: 'https://v2.discours.io' +schema: 'http://127.0.0.1:8080' +#schema: 'https://v2.discours.io' generates: src/graphql/introspec.gen.ts: plugins: diff --git a/src/components/App.tsx b/src/components/App.tsx index 3cc6d408..6b3416fa 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -27,6 +27,7 @@ import { ProjectsPage } from '../pages/about/projects.page' import { TermsOfUsePage } from '../pages/about/termsOfUse.page' import { ThanksPage } from '../pages/about/thanks.page' import { CreatePage } from '../pages/create.page' +import { EditPage } from '../pages/edit.page' import { ConnectPage } from '../pages/connect.page' import { InboxPage } from '../pages/inbox.page' import { LayoutShoutsPage } from '../pages/layoutShouts.page' @@ -45,7 +46,8 @@ const pagesMap: Record> = { expo: LayoutShoutsPage, connect: ConnectPage, create: CreatePage, - createSettings: CreatePage, + edit: EditPage, + editSettings: EditPage, home: HomePage, topics: AllTopicsPage, topic: TopicPage, diff --git a/src/components/Article/CommentsTree.tsx b/src/components/Article/CommentsTree.tsx index 1a2d8b83..81daa4e0 100644 --- a/src/components/Article/CommentsTree.tsx +++ b/src/components/Article/CommentsTree.tsx @@ -52,8 +52,6 @@ export const CommentsTree = (props: Props) => { Object.values(reactionEntities).filter((reaction) => reaction.kind === 'COMMENT') ) - console.log(JSON.parse(JSON.stringify(reactionEntities))) - const sortedComments = createMemo(() => { let newSortedComments = [...comments()] newSortedComments = newSortedComments.sort(byCreated) diff --git a/src/components/Article/FullArticle.tsx b/src/components/Article/FullArticle.tsx index f3abaa45..9eef962c 100644 --- a/src/components/Article/FullArticle.tsx +++ b/src/components/Article/FullArticle.tsx @@ -208,10 +208,12 @@ export const FullArticle = (props: ArticleProps) => { -
- + {t('Edit')} diff --git a/src/components/Editor/Editor.tsx b/src/components/Editor/Editor.tsx index e6a8c792..bd3db52e 100644 --- a/src/components/Editor/Editor.tsx +++ b/src/components/Editor/Editor.tsx @@ -30,7 +30,7 @@ import { TrailingNode } from './extensions/TrailingNode' import { EditorBubbleMenu } from './EditorBubbleMenu/EditorBubbleMenu' import { EditorFloatingMenu } from './EditorFloatingMenu' import * as Y from 'yjs' -import { WebrtcProvider } from 'y-webrtc' +// import { WebrtcProvider } from 'y-webrtc' import { CollaborationCursor } from '@tiptap/extension-collaboration-cursor' import { Collaboration } from '@tiptap/extension-collaboration' import './Prosemirror.scss' @@ -40,7 +40,7 @@ import uniqolor from 'uniqolor' import { HocuspocusProvider } from '@hocuspocus/provider' type EditorProps = { - shoutId: number + shoutSlug: string initialContent?: string onChange: (text: string) => void } @@ -53,12 +53,12 @@ export const Editor = (props: EditorProps) => { const { t } = useLocalize() const { user } = useSession() - const docName = `shout-${props.shoutId}` + const docName = `shout-${props.shoutSlug}` if (!providers[docName]) { providers[docName] = new HocuspocusProvider({ - // url: 'wss://hocuspocus.discours.io', - url: 'ws://localhost:4242', + url: 'wss://hocuspocus.discours.io', + // url: 'ws://localhost:4242', name: docName, document: yDoc }) @@ -88,6 +88,7 @@ export const Editor = (props: EditorProps) => { const editor = createTiptapEditor(() => ({ element: editorElRef.current, + content: props.initialContent, extensions: [ Document, Text, diff --git a/src/components/Editor/EditorBubbleMenu/EditorBubbleMenu.tsx b/src/components/Editor/EditorBubbleMenu/EditorBubbleMenu.tsx index 352da9a8..cf095243 100644 --- a/src/components/Editor/EditorBubbleMenu/EditorBubbleMenu.tsx +++ b/src/components/Editor/EditorBubbleMenu/EditorBubbleMenu.tsx @@ -1,4 +1,4 @@ -import { Switch, Match, createSignal, Show, createEffect } from 'solid-js' +import { Switch, Match, createSignal, Show } from 'solid-js' import type { Editor } from '@tiptap/core' import styles from './EditorBubbleMenu.module.scss' import { Icon } from '../../_shared/Icon' @@ -26,10 +26,6 @@ export const EditorBubbleMenu = (props: BubbleMenuProps) => { } ) - createEffect(() => { - console.log('!!! editor:', props.editor) - }) - const isBold = isActive('bold') const isItalic = isActive('italic') const isH1 = isActive('heading', { level: 1 }) diff --git a/src/components/Nav/HeaderAuth.tsx b/src/components/Nav/HeaderAuth.tsx index 830493d4..8183d7e6 100644 --- a/src/components/Nav/HeaderAuth.tsx +++ b/src/components/Nav/HeaderAuth.tsx @@ -44,7 +44,7 @@ export const HeaderAuth = (props: HeaderAuthProps) => {
- + {props.topic.title} diff --git a/src/components/Views/Create.module.scss b/src/components/Views/Edit.module.scss similarity index 96% rename from src/components/Views/Create.module.scss rename to src/components/Views/Edit.module.scss index a956c195..80839c8d 100644 --- a/src/components/Views/Create.module.scss +++ b/src/components/Views/Edit.module.scss @@ -43,8 +43,8 @@ } } -.createSettings, -.create { +.editSettings, +.edit { display: none; &.visible { diff --git a/src/components/Views/Create.tsx b/src/components/Views/Edit.tsx similarity index 80% rename from src/components/Views/Create.tsx rename to src/components/Views/Edit.tsx index 6f895276..e09ae27f 100644 --- a/src/components/Views/Create.tsx +++ b/src/components/Views/Edit.tsx @@ -1,15 +1,14 @@ -import { createSignal, lazy, onMount, Show, Suspense } from 'solid-js' -import { Loading } from '../_shared/Loading' +import { createSignal, onMount, Show } from 'solid-js' import { useLocalize } from '../../context/localize' import { clsx } from 'clsx' -import styles from './Create.module.scss' +import styles from './Edit.module.scss' import { Title } from '@solidjs/meta' import { createStore } from 'solid-js/store' -import type { Topic } from '../../graphql/types.gen' +import type { Shout, Topic } from '../../graphql/types.gen' import { apiClient } from '../../utils/apiClient' import { TopicSelect } from '../Editor/TopicSelect/TopicSelect' import { router, useRouter } from '../../stores/router' -import { getPagePath } from '@nanostores/router' +import { getPagePath, openPage } from '@nanostores/router' import { translit } from '../../utils/ru2en' import { Editor } from '../Editor/Editor' @@ -18,12 +17,16 @@ type ShoutForm = { title: string subtitle: string selectedTopics: Topic[] - mainTopic: Topic + mainTopic: string body: string coverImageUrl: string } -export const CreateView = () => { +type EditViewProps = { + shout: Shout +} + +export const EditView = (props: EditViewProps) => { const { t } = useLocalize() const [topics, setTopics] = createSignal(null) @@ -32,13 +35,13 @@ export const CreateView = () => { const [isSlugChanged, setIsSlugChanged] = createSignal(false) const [form, setForm] = createStore({ - slug: '', - title: '', - subtitle: '', - selectedTopics: [], - mainTopic: null, - body: '', - coverImageUrl: '' + slug: props.shout.slug, + title: props.shout.title, + subtitle: props.shout.subtitle, + selectedTopics: props.shout.topics, + mainTopic: props.shout.mainTopic, + body: props.shout.body, + coverImageUrl: props.shout.cover }) onMount(async () => { @@ -49,18 +52,18 @@ export const CreateView = () => { const handleFormSubmit = async (e) => { e.preventDefault() - const newShout = await apiClient.createArticle({ - article: { - slug: form.slug, - title: form.title, - subtitle: form.subtitle, - body: form.body, - topics: form.selectedTopics.map((topic) => topic.slug), - mainTopic: form.selectedTopics[0].slug - } - }) + // const newShout = await apiClient.updateArticle({ + // article: { + // slug: form.slug, + // title: form.title, + // subtitle: form.subtitle, + // body: form.body, + // topics: form.selectedTopics.map((topic) => topic.slug), + // mainTopic: form.selectedTopics[0].slug + // } + // }) - router.open(getPagePath(router, 'article', { slug: newShout.slug })) + // openPage(getPagePath(router, 'article', { slug: newShout.slug })) } const handleTitleInputChange = (e) => { @@ -92,8 +95,8 @@ export const CreateView = () => {
{ onChange={(e) => setForm('subtitle', e.currentTarget.value)} /> - setForm('body', body)} /> + setForm('body', body)} + />
{/**/} - Настройки + + Настройки +

Настройки публикации

@@ -206,8 +215,8 @@ export const CreateView = () => { Проверьте ещё раз введённые данные, если всё верно, вы можете сохранить или опубликовать ваш текст

- {/**/} - Назад + + Назад @@ -222,4 +231,4 @@ export const CreateView = () => { ) } -export default CreateView +export default EditView diff --git a/src/graphql/mutation/article-create.ts b/src/graphql/mutation/article-create.ts index 90ad3e7e..f38b3240 100644 --- a/src/graphql/mutation/article-create.ts +++ b/src/graphql/mutation/article-create.ts @@ -10,18 +10,6 @@ export default gql` title subtitle body - topics { - id - title - slug - } - authors { - id - name - slug - userpic - caption - } } } } diff --git a/src/graphql/mutation/draft-create.ts b/src/graphql/mutation/draft-create.ts deleted file mode 100644 index 6aae7886..00000000 --- a/src/graphql/mutation/draft-create.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { gql } from '@urql/core' - -export default gql` - mutation DraftCreateMutation($draft: DraftInput!) { - createDraft(draft: $draft) { - error - draft { - id - slug - title - subtitle - body - topics { - # id - title - slug - } - authors { - id - name - slug - userpic - caption - } - } - } - } -` diff --git a/src/graphql/mutation/draft-destroy.ts b/src/graphql/mutation/draft-destroy.ts deleted file mode 100644 index e01f8c6b..00000000 --- a/src/graphql/mutation/draft-destroy.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { gql } from '@urql/core' - -export default gql` - mutation DraftDestroyMutation($draft: Int!) { - deleteDraft(draft: $draft) { - error - } - } -` diff --git a/src/graphql/mutation/draft-to-shout.ts b/src/graphql/mutation/draft-to-shout.ts deleted file mode 100644 index 882e49f0..00000000 --- a/src/graphql/mutation/draft-to-shout.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { gql } from '@urql/core' - -export default gql` - mutation ShoutFromDraftMutation($draft: Int!) { - draftToShout(draft: $draft) { - error - shout { - _id: slug - slug - title - subtitle - body - topics { - # id - title - slug - } - authors { - id - name - slug - userpic - caption - } - } - } - } -` diff --git a/src/graphql/mutation/draft-update.ts b/src/graphql/mutation/draft-update.ts deleted file mode 100644 index 55dabcdc..00000000 --- a/src/graphql/mutation/draft-update.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { gql } from '@urql/core' - -export default gql` - mutation DraftUpdateMutation($draft: DraftInput!) { - updateDraft(draft: $draft) { - error - draft { - id - slug - title - subtitle - body - topics { - # id - title - slug - } - authors { - id - name - slug - userpic - caption - } - } - } - } -` diff --git a/src/graphql/query/my-drafts.ts b/src/graphql/query/my-drafts.ts deleted file mode 100644 index b5dd8c1a..00000000 --- a/src/graphql/query/my-drafts.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { gql } from '@urql/core' - -export default gql` - query MyDraftsQuery { - loadDrafts { - authors { - id - slug - name - pic - } - createdAt - body - title - } - } -` diff --git a/src/graphql/types.gen.ts b/src/graphql/types.gen.ts index 11a6b2c1..7c3dc987 100644 --- a/src/graphql/types.gen.ts +++ b/src/graphql/types.gen.ts @@ -105,30 +105,6 @@ export type Community = { slug: Scalars['String'] } -export type DraftCollab = { - authors: Array> - body?: Maybe - chat?: Maybe - cover?: Maybe - createdAt: Scalars['Int'] - layout?: Maybe - slug?: Maybe - subtitle?: Maybe - title?: Maybe - topics?: Maybe>> - updatedAt?: Maybe -} - -export type DraftInput = { - authors?: InputMaybe>> - body?: InputMaybe - cover?: InputMaybe - slug?: InputMaybe - subtitle?: InputMaybe - title?: InputMaybe - topics?: InputMaybe>> -} - export enum FollowingEntity { Author = 'AUTHOR', Community = 'COMMUNITY', @@ -185,28 +161,23 @@ export type MessagesBy = { export type Mutation = { confirmEmail: AuthResult createChat: Result - createDraft: Result createMessage: Result createReaction: Result createShout: Result createTopic: Result deleteChat: Result - deleteDraft: Result deleteMessage: Result deleteReaction: Result deleteShout: Result destroyTopic: Result follow: Result getSession: AuthResult - inviteAccept: Result - inviteAuthor: Result markAsRead: Result rateUser: Result registerUser: AuthResult sendLink: Result unfollow: Result updateChat: Result - updateDraft: Result updateMessage: Result updateOnlineStatus: Result updateProfile: Result @@ -224,10 +195,6 @@ export type MutationCreateChatArgs = { title?: InputMaybe } -export type MutationCreateDraftArgs = { - draft: DraftInput -} - export type MutationCreateMessageArgs = { body: Scalars['String'] chat: Scalars['String'] @@ -250,10 +217,6 @@ export type MutationDeleteChatArgs = { chatId: Scalars['String'] } -export type MutationDeleteDraftArgs = { - draft: Scalars['Int'] -} - export type MutationDeleteMessageArgs = { chatId: Scalars['String'] id: Scalars['Int'] @@ -276,15 +239,6 @@ export type MutationFollowArgs = { what: FollowingEntity } -export type MutationInviteAcceptArgs = { - draft: Scalars['Int'] -} - -export type MutationInviteAuthorArgs = { - author: Scalars['Int'] - draft: Scalars['Int'] -} - export type MutationMarkAsReadArgs = { chatId: Scalars['String'] ids: Array> @@ -316,10 +270,6 @@ export type MutationUpdateChatArgs = { chat: ChatInput } -export type MutationUpdateDraftArgs = { - draft: DraftInput -} - export type MutationUpdateMessageArgs = { body: Scalars['String'] chatId: Scalars['String'] @@ -375,13 +325,13 @@ export type Query = { isEmailUsed: Scalars['Boolean'] loadAuthorsBy: Array> loadChats: Result - loadDrafts: Array> loadMessagesBy: Result loadReactionsBy: Array> loadRecipients: Result loadShout?: Maybe loadShouts: Array> markdownBody: Scalars['String'] + myFeed?: Maybe>> searchMessages: Result searchRecipients: Result signIn: AuthResult @@ -447,6 +397,10 @@ export type QueryMarkdownBodyArgs = { body: Scalars['String'] } +export type QueryMyFeedArgs = { + options?: InputMaybe +} + export type QuerySearchMessagesArgs = { by: MessagesBy limit?: InputMaybe @@ -573,7 +527,6 @@ export type Result = { chats?: Maybe>> communities?: Maybe>> community?: Maybe - drafts?: Maybe>> error?: Maybe members?: Maybe>> message?: Maybe @@ -585,7 +538,6 @@ export type Result = { slugs?: Maybe>> topic?: Maybe topics?: Maybe>> - uids?: Maybe>> } export type Role = { @@ -610,7 +562,6 @@ export type Shout = { mainTopic?: Maybe media?: Maybe publishedAt?: Maybe - publishedBy?: Maybe slug: Scalars['String'] stat?: Maybe subtitle?: Maybe @@ -624,7 +575,7 @@ export type Shout = { export type ShoutInput = { authors?: InputMaybe>> - body: Scalars['String'] + body?: InputMaybe community?: InputMaybe mainTopic?: InputMaybe slug?: InputMaybe @@ -676,6 +627,7 @@ export type Token = { export type Topic = { body?: Maybe community: Community + id: Scalars['Int'] oid?: Maybe pic?: Maybe slug: Scalars['String'] diff --git a/src/pages/create.page.tsx b/src/pages/create.page.tsx index e8deb8ea..8eb9766e 100644 --- a/src/pages/create.page.tsx +++ b/src/pages/create.page.tsx @@ -1,22 +1,19 @@ -import { lazy, Show, Suspense } from 'solid-js' import { PageLayout } from '../components/_shared/PageLayout' import { Loading } from '../components/_shared/Loading' -import { useSession } from '../context/session' - -const CreateView = lazy(() => import('../components/Views/Create')) +import { onMount } from 'solid-js' +import { apiClient } from '../utils/apiClient' +import { router } from '../stores/router' +import { redirectPage } from '@nanostores/router' export const CreatePage = () => { - const { isAuthenticated, isSessionLoaded } = useSession() + onMount(async () => { + const shout = await apiClient.createArticle({ article: {} }) + redirectPage(router, 'edit', { shoutSlug: shout.slug }) + }) return ( - - - }> - - - - + ) } diff --git a/src/pages/createSettings.page.route.ts b/src/pages/edit.page.route.ts similarity index 65% rename from src/pages/createSettings.page.route.ts rename to src/pages/edit.page.route.ts index 84550820..2c20acbb 100644 --- a/src/pages/createSettings.page.route.ts +++ b/src/pages/edit.page.route.ts @@ -1,4 +1,4 @@ import { ROUTES } from '../stores/router' import { getServerRoute } from '../utils/getServerRoute' -export default getServerRoute(ROUTES.createSettings) +export default getServerRoute(ROUTES.edit) diff --git a/src/pages/edit.page.tsx b/src/pages/edit.page.tsx new file mode 100644 index 00000000..fe511df9 --- /dev/null +++ b/src/pages/edit.page.tsx @@ -0,0 +1,40 @@ +import { createMemo, createSignal, lazy, onMount, Show, Suspense } from 'solid-js' +import { PageLayout } from '../components/_shared/PageLayout' +import { Loading } from '../components/_shared/Loading' +import { useSession } from '../context/session' +import { Shout } from '../graphql/types.gen' +import { useRouter } from '../stores/router' +import { apiClient } from '../utils/apiClient' + +const EditView = lazy(() => import('../components/Views/Edit')) + +export const EditPage = () => { + const { isAuthenticated, isSessionLoaded } = useSession() + + const { page } = useRouter() + + const shoutSlug = createMemo(() => (page().params as Record<'shoutSlug', string>).shoutSlug) + + const [shout, setShout] = createSignal(null) + + onMount(async () => { + const loadedShout = await apiClient.getShout(shoutSlug()) + setShout(loadedShout) + }) + + return ( + + + + + }> + + + + + + + ) +} + +export const Page = EditPage diff --git a/src/pages/editSettings.page.route.ts b/src/pages/editSettings.page.route.ts new file mode 100644 index 00000000..c4521906 --- /dev/null +++ b/src/pages/editSettings.page.route.ts @@ -0,0 +1,4 @@ +import { ROUTES } from '../stores/router' +import { getServerRoute } from '../utils/getServerRoute' + +export default getServerRoute(ROUTES.editSettings) diff --git a/src/stores/editor.ts b/src/stores/editor.ts deleted file mode 100644 index c79bb596..00000000 --- a/src/stores/editor.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { createStorageSignal } from '@solid-primitives/storage' -import type { Reaction } from '../graphql/types.gen' -import { createSignal } from 'solid-js' - -// TODO: store drafts -// import type { Draft } from '../components/EditorExample/store/context' - -interface Collab { - authors: string[] // slugs - invites?: string[] - createdAt: Date - body?: string - title?: string -} - -export const drafts = createStorageSignal<{ [key: string]: string }>('drafts', {}) // save drafts on device -export const [collabs, setCollabs] = createSignal([]) // save collabs in backend or in p2p network -export const [editorReactions, setReactions] = createSignal([]) -/* - -TODO: approvals and proposals derived stores - -const approvals = computed( - reactions, - (rdict) => Object.values(rdict) - .filter((r: Reaction) => r.kind === ReactionKind.Accept) -) -const proposals = computed( - reactions, - (rdict) => Object.values(rdict) - .filter((r: Reaction) => r.kind === ReactionKind.Propose) -) -*/ diff --git a/src/stores/router.ts b/src/stores/router.ts index 94e8789f..9d6494db 100644 --- a/src/stores/router.ts +++ b/src/stores/router.ts @@ -9,7 +9,8 @@ export const ROUTES = { inbox: '/inbox', connect: '/connect', create: '/create', - createSettings: '/create/settings', + edit: '/edit/:shoutSlug', + editSettings: '/edit/:shoutSlug/settings', topics: '/topics', topic: '/topic/:slug', authors: '/authors',