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

View File

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

View File

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

View File

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

View File

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

View File

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