Skip to content

Commit

Permalink
fix: unchanged summary
Browse files Browse the repository at this point in the history
  • Loading branch information
GZTimeWalker committed Sep 5, 2022
1 parent 111a8d4 commit 0b09a1b
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 89 deletions.
181 changes: 92 additions & 89 deletions GZCTF/ClientApp/src/pages/posts/[postId]/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import { mdiCheck, mdiContentSaveOutline, mdiDeleteOutline } from '@mdi/js'
import { Icon } from '@mdi/react'
import StickyHeader from '@Components/StickyHeader'
import WithNavBar from '@Components/WithNavbar'
import WithRole from '@Components/WithRole'
import { showErrorNotification } from '@Utils/ApiErrorHandler'
import api, { PostEditModel } from '@Api'
import api, { PostEditModel, Role } from '@Api'

const PostEdit: FC = () => {
const { postId } = useParams()
Expand Down Expand Up @@ -126,101 +127,103 @@ const PostEdit: FC = () => {

return (
<WithNavBar>
<StickyHeader />
<Stack mt={30}>
<Group position="apart">
<Title
order={1}
style={{
color: theme.fn.rgba(
theme.colorScheme === 'dark' ? theme.colors.white[6] : theme.colors.gray[7],
0.5
),
}}
>
{`> ${postId === 'new' ? '新建' : '编辑'}文章`}
</Title>
<Group position="right">
{postId?.length === 8 && (
<WithRole requiredRole={Role.Admin}>
<StickyHeader />
<Stack mt={30}>
<Group position="apart">
<Title
order={1}
style={{
color: theme.fn.rgba(
theme.colorScheme === 'dark' ? theme.colors.white[6] : theme.colors.gray[7],
0.5
),
}}
>
{`> ${postId === 'new' ? '新建' : '编辑'}文章`}
</Title>
<Group position="right">
{postId?.length === 8 && (
<Button
disabled={disabled}
color="red"
leftIcon={<Icon path={mdiDeleteOutline} size={1} />}
variant="outline"
onClick={() =>
modals.openConfirmModal({
title: `删除文章`,
children: <Text size="sm">你确定要删除文章 "{post.title}" 吗?</Text>,
centered: true,
onConfirm: onDelete,
labels: { confirm: '确认', cancel: '取消' },
confirmProps: { color: 'red' },
})
}
>
删除文章
</Button>
)}
<Button
disabled={disabled}
color="red"
leftIcon={<Icon path={mdiDeleteOutline} size={1} />}
variant="outline"
onClick={() =>
modals.openConfirmModal({
title: `删除文章`,
children: <Text size="sm">你确定要删除文章 "{post.title}" 吗?</Text>,
centered: true,
onConfirm: onDelete,
labels: { confirm: '确认', cancel: '取消' },
confirmProps: { color: 'red' },
})
}
leftIcon={<Icon path={mdiContentSaveOutline} size={1} />}
onClick={onUpdate}
>
删除文章
{`${postId === 'new' ? '创建' : '保存'}文章`}
</Button>
)}
<Button
disabled={disabled}
leftIcon={<Icon path={mdiContentSaveOutline} size={1} />}
onClick={onUpdate}
>
{`${postId === 'new' ? '创建' : '保存'}文章`}
</Button>
</Group>
</Group>
</Group>
<Group grow>
<TextInput
label="文章标题"
value={post.title}
onChange={(e) => setPost({ ...post, title: e.currentTarget.value })}
<Group grow>
<TextInput
label="文章标题"
value={post.title}
onChange={(e) => setPost({ ...post, title: e.currentTarget.value })}
/>
<MultiSelect
label="文章标签"
data={tags.map((o) => ({ value: o, label: o })) || []}
getCreateLabel={(query) => `+ 添加标签 "${query}"`}
maxSelectedValues={5}
value={post?.tags ?? []}
onChange={(values) => setPost({ ...post, tags: values })}
onCreate={(query) => {
const item = { value: query, label: query }
setTags([...tags, query])
return item
}}
searchable
creatable
/>
</Group>
<Textarea
label={
<Group spacing="sm">
<Text size="sm">文章梗概</Text>
<Text size="xs" color="dimmed">
支持 markdown 语法
</Text>
</Group>
}
value={post.summary}
onChange={(e) => setPost({ ...post, summary: e.currentTarget.value })}
minRows={3}
maxRows={3}
/>
<MultiSelect
label="文章标签"
data={tags.map((o) => ({ value: o, label: o })) || []}
getCreateLabel={(query) => `+ 添加标签 "${query}"`}
maxSelectedValues={5}
value={post?.tags ?? []}
onChange={(values) => setPost({ ...post, tags: values })}
onCreate={(query) => {
const item = { value: query, label: query }
setTags([...tags, query])
return item
}}
searchable
creatable
<Textarea
label={
<Group spacing="sm">
<Text size="sm">文章内容</Text>
<Text size="xs" color="dimmed">
支持 markdown 语法
</Text>
</Group>
}
value={post.content}
onChange={(e) => setPost({ ...post, content: e.currentTarget.value })}
minRows={16}
maxRows={16}
/>
</Group>
<Textarea
label={
<Group spacing="sm">
<Text size="sm">文章梗概</Text>
<Text size="xs" color="dimmed">
支持 markdown 语法
</Text>
</Group>
}
value={post.summary}
onChange={(e) => setPost({ ...post, summary: e.currentTarget.value })}
minRows={3}
maxRows={3}
/>
<Textarea
label={
<Group spacing="sm">
<Text size="sm">文章内容</Text>
<Text size="xs" color="dimmed">
支持 markdown 语法
</Text>
</Group>
}
value={post.content}
onChange={(e) => setPost({ ...post, content: e.currentTarget.value })}
minRows={16}
maxRows={16}
/>
</Stack>
</Stack>
</WithRole>
</WithNavBar>
)
}
Expand Down
1 change: 1 addition & 0 deletions GZCTF/Models/Data/Post.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class Post
internal void Update(PostEditModel model, UserInfo user)
{
Title = model.Title;
Summary = model.Summary;
Content = model.Content;
IsPinned = model.IsPinned;
Tags = model.Tags.ToList();
Expand Down

0 comments on commit 0b09a1b

Please sign in to comment.