Merge branch 'editor_float_image' into drafts-2

# Conflicts:
#	src/components/Editor/Editor.tsx
This commit is contained in:
bniwredyc 2023-05-07 17:15:30 +02:00
parent 1f15a1f4e7
commit afbaa3791e
7 changed files with 49 additions and 30 deletions

View File

@ -97,3 +97,14 @@
} }
} }
} }
.inputContainer {
position: relative;
.validationError {
position: absolute;
top: 100%;
font-size: small;
color: #f00;
}
}

View File

@ -6,9 +6,7 @@ import { Title } from '@solidjs/meta'
import type { Shout, Topic } from '../../graphql/types.gen' import type { Shout, Topic } from '../../graphql/types.gen'
import { apiClient } from '../../utils/apiClient' import { apiClient } from '../../utils/apiClient'
import { TopicSelect } from '../Editor/TopicSelect/TopicSelect' import { TopicSelect } from '../Editor/TopicSelect/TopicSelect'
import { router, useRouter } from '../../stores/router' import { useRouter } from '../../stores/router'
import { openPage } from '@nanostores/router'
import { translit } from '../../utils/ru2en'
import { Editor } from '../Editor/Editor' import { Editor } from '../Editor/Editor'
import { Panel } from '../Editor/Panel' import { Panel } from '../Editor/Panel'
import { useEditorContext } from '../../context/editor' import { useEditorContext } from '../../context/editor'
@ -32,6 +30,7 @@ export const EditView = (props: EditViewProps) => {
const [isSlugChanged, setIsSlugChanged] = createSignal(false) const [isSlugChanged, setIsSlugChanged] = createSignal(false)
setForm({ setForm({
shoutId: props.shout.id,
slug: props.shout.slug, slug: props.shout.slug,
title: props.shout.title, title: props.shout.title,
subtitle: props.shout.subtitle, subtitle: props.shout.subtitle,
@ -82,17 +81,21 @@ export const EditView = (props: EditViewProps) => {
[styles.visible]: page().route === 'edit' [styles.visible]: page().route === 'edit'
})} })}
> >
<input <div class={styles.inputContainer}>
class={styles.titleInput} <input
type="text" class={styles.titleInput}
name="title" type="text"
id="title" name="title"
placeholder="Заголовок" id="title"
autocomplete="off" placeholder="Заголовок"
value={form.title} autocomplete="off"
onInput={handleTitleInputChange} value={form.title}
/> onInput={handleTitleInputChange}
<Show when={formErrors.title}>{formErrors.title}</Show> />
<Show when={formErrors.title}>
<div class={styles.validationError}>{formErrors.title}</div>
</Show>
</div>
<input <input
class={styles.subtitleInput} class={styles.subtitleInput}

View File

@ -1,7 +1,7 @@
import type { JSX } from 'solid-js' import type { JSX } from 'solid-js'
import { Accessor, createContext, createEffect, createSignal, useContext } from 'solid-js' import { Accessor, createContext, createSignal, useContext } from 'solid-js'
import { createStore, SetStoreFunction } from 'solid-js/store' import { createStore, SetStoreFunction } from 'solid-js/store'
import { InputMaybe, Scalars, Shout, Topic } from '../graphql/types.gen' import { Topic } from '../graphql/types.gen'
import { apiClient } from '../utils/apiClient' import { apiClient } from '../utils/apiClient'
import { useLocalize } from './localize' import { useLocalize } from './localize'
import { useSnackbar } from './snackbar' import { useSnackbar } from './snackbar'
@ -12,6 +12,7 @@ type WordCounter = {
} }
type ShoutForm = { type ShoutForm = {
shoutId: number
slug: string slug: string
title: string title: string
subtitle: string subtitle: string
@ -69,8 +70,8 @@ export const EditorProvider = (props: { children: JSX.Element }) => {
try { try {
await apiClient.updateArticle({ await apiClient.updateArticle({
slug: form.slug, shoutId: form.shoutId,
article: { shoutInput: {
body: form.body, body: form.body,
topics: form.selectedTopics.map((topic) => topic.slug), topics: form.selectedTopics.map((topic) => topic.slug),
// authors?: InputMaybe<Array<InputMaybe<Scalars['String']>>> // authors?: InputMaybe<Array<InputMaybe<Scalars['String']>>>

View File

@ -1,7 +1,7 @@
import { gql } from '@urql/core' import { gql } from '@urql/core'
export default gql` export default gql`
mutation UpdateShoutMutation($slug: String!) { mutation PublishShoutMutation($slug: String!) {
publishShout(slug: $slug) { publishShout(slug: $slug) {
error error
shout { shout {

View File

@ -1,8 +1,8 @@
import { gql } from '@urql/core' import { gql } from '@urql/core'
export default gql` export default gql`
mutation UpdateShoutMutation($slug: String!, $shout: ShoutInput!) { mutation UpdateShoutMutation($shoutId: Int!, $shoutInput: ShoutInput!) {
updateShout(slug: $slug, inp: $shout) { updateShout(shoutId: $shoutId, shoutInput: $shoutInput) {
error error
shout { shout {
id id

View File

@ -228,7 +228,7 @@ export type MutationDeleteReactionArgs = {
} }
export type MutationDeleteShoutArgs = { export type MutationDeleteShoutArgs = {
slug: Scalars['String'] shout_id: Scalars['Int']
} }
export type MutationDestroyTopicArgs = { export type MutationDestroyTopicArgs = {
@ -246,8 +246,8 @@ export type MutationMarkAsReadArgs = {
} }
export type MutationPublishShoutArgs = { export type MutationPublishShoutArgs = {
inp: ShoutInput shout_id: Scalars['Int']
slug: Scalars['String'] shout_input?: InputMaybe<ShoutInput>
} }
export type MutationRateUserArgs = { export type MutationRateUserArgs = {
@ -292,8 +292,8 @@ export type MutationUpdateReactionArgs = {
} }
export type MutationUpdateShoutArgs = { export type MutationUpdateShoutArgs = {
inp: ShoutInput shout_id: Scalars['Int']
slug: Scalars['String'] shout_input: ShoutInput
} }
export type MutationUpdateTopicArgs = { export type MutationUpdateTopicArgs = {

View File

@ -248,10 +248,14 @@ export const apiClient = {
console.debug('[createArticle]:', response.data) console.debug('[createArticle]:', response.data)
return response.data.createShout.shout return response.data.createShout.shout
}, },
updateArticle: async ({ slug, article }: { slug: string; article: ShoutInput }): Promise<Shout> => { updateArticle: async ({
const response = await privateGraphQLClient shoutId,
.mutation(updateArticle, { slug, shout: article }) shoutInput
.toPromise() }: {
shoutId: number
shoutInput: ShoutInput
}): Promise<Shout> => {
const response = await privateGraphQLClient.mutation(updateArticle, { shoutId, shoutInput }).toPromise()
console.debug('[updateArticle]:', response.data) console.debug('[updateArticle]:', response.data)
return response.data.updateShout.shout return response.data.updateShout.shout
}, },