pull/51/head
sunface 4 years ago
parent 8c2bf9f379
commit 001609b801

@ -18,7 +18,7 @@ import Empty from "components/empty"
import { IDType } from "src/types/id" import { IDType } from "src/types/id"
var validator = require('validator'); var validator = require('validator');
const newSeries: Story = { title: '', brief: '', cover: '',type: IDType.Series } const newSeries: Story = { title: '', brief: '', cover: '', type: IDType.Series }
const PostsPage = () => { const PostsPage = () => {
const [currentSeries, setCurrentSeries] = useState(null) const [currentSeries, setCurrentSeries] = useState(null)
const [posts, setPosts] = useState([]) const [posts, setPosts] = useState([])
@ -75,11 +75,8 @@ const PostsPage = () => {
} }
const editPost = (post: Story) => { const editPost = (post: Story) => {
if (post.url.trim() === "") { console.log(post)
router.push(`/editor/post/${post.id}`) setCurrentSeries(post)
} else {
setCurrentSeries(post)
}
} }
const onDeletePost = async (id) => { const onDeletePost = async (id) => {
@ -100,55 +97,71 @@ const PostsPage = () => {
<Sidebar routes={editorLinks} title="创作中心" /> <Sidebar routes={editorLinks} title="创作中心" />
<Card ml="4" p="6" width="100%"> <Card ml="4" p="6" width="100%">
{currentSeries ? {currentSeries ?
<Formik <>
initialValues={currentSeries} <Formik
onSubmit={submitPost} initialValues={currentSeries}
> onSubmit={submitPost}
{(props) => ( >
<Form> {(props) => (
<VStack spacing="6"> <Form>
<Field name="title" validate={validateTitle}> <VStack spacing="6">
{({ field, form }) => ( <Field name="title" validate={validateTitle}>
<FormControl isInvalid={form.errors.title && form.touched.title} > {({ field, form }) => (
<FormLabel></FormLabel> <FormControl isInvalid={form.errors.title && form.touched.title} >
<Input {...field} placeholder="name" /> <FormLabel></FormLabel>
<FormErrorMessage>{form.errors.title}</FormErrorMessage> <Input {...field} placeholder="name" />
</FormControl> <FormErrorMessage>{form.errors.title}</FormErrorMessage>
)} </FormControl>
</Field> )}
<Field name="cover" validate={validateUrl}> </Field>
{({ field, form }) => ( <Field name="cover" validate={validateUrl}>
<FormControl isInvalid={form.errors.cover && form.touched.cover}> {({ field, form }) => (
<FormLabel></FormLabel> <FormControl isInvalid={form.errors.cover && form.touched.cover}>
<Input {...field} placeholder="https://..." /> <FormLabel></FormLabel>
<FormErrorMessage>{form.errors.cover}</FormErrorMessage> <Input {...field} placeholder="https://..." />
</FormControl> <FormErrorMessage>{form.errors.cover}</FormErrorMessage>
)} </FormControl>
</Field> )}
<Field name="brief" validate={validateBrief}> </Field>
{({ field, form }) => ( <Field name="brief" validate={validateBrief}>
<FormControl isInvalid={form.errors.brief && form.touched.brief}> {({ field, form }) => (
<FormLabel></FormLabel> <FormControl isInvalid={form.errors.brief && form.touched.brief}>
<Textarea {...field} placeholder="在本系列文章中,我们将..."></Textarea> <FormLabel></FormLabel>
<FormErrorMessage>{form.errors.brief}</FormErrorMessage> <Textarea {...field} placeholder="在本系列文章中,我们将..."></Textarea>
</FormControl> <FormErrorMessage>{form.errors.brief}</FormErrorMessage>
)} </FormControl>
</Field> )}
</VStack> </Field>
<Box mt={6}> <Field>
<Button {({ field, form }) => (
colorScheme="teal" <FormControl isInvalid={form.errors.brief && form.touched.brief}>
variant="outline" <Divider mt="0" mb="6" />
type="submit" <FormLabel></FormLabel>
_focus={null} <Button variant="ghost"></Button>
> <Divider mt="6" mb="6" />
</FormControl>
)}
</Field>
</VStack>
<Box mt={6}>
<Button
colorScheme="teal"
variant="outline"
type="submit"
_focus={null}
>
</Button> </Button>
<Button variant="ghost" ml="4" _focus={null} onClick={() => setCurrentSeries(null)}></Button> <Button variant="ghost" ml="4" _focus={null} onClick={() => setCurrentSeries(null)}></Button>
</Box> </Box>
</Form> </Form>
)} )}
</Formik> : </Formik>
</>
:
<> <>
<Flex alignItems="center" justify="space-between"> <Flex alignItems="center" justify="space-between">
<Heading size="md">({posts.length})</Heading> <Heading size="md">({posts.length})</Heading>
@ -161,7 +174,7 @@ const PostsPage = () => {
<VStack mt="4"> <VStack mt="4">
{posts.map(post => {posts.map(post =>
<Box width="100%" key={post.id}> <Box width="100%" key={post.id}>
<TextStoryCard story={post} showActions={true} mt="4" onEdit={() => editPost(post)} onDelete={() => onDeletePost(post.id)} showSource={false}/> <TextStoryCard story={post} showActions={true} mt="4" onEdit={() => editPost(post)} onDelete={() => onDeletePost(post.id)} showSource={false} />
<Divider mt="5" /> <Divider mt="5" />
</Box> </Box>
)} )}

@ -60,10 +60,13 @@ func SubmitStory(c *gin.Context) (map[string]string, *e.Error) {
if !user.Role.IsCreator() { if !user.Role.IsCreator() {
return nil, e.New(http.StatusForbidden, e.NoEditorPermission) return nil, e.New(http.StatusForbidden, e.NoEditorPermission)
} }
if len(post.Md) <= config.Data.Posts.BriefMaxLen {
post.Brief = post.Md if post.Type == models.IDTypePost {
} else { if len(post.Md) <= config.Data.Posts.BriefMaxLen {
post.Brief = string([]rune(post.Md)[:config.Data.Posts.BriefMaxLen]) post.Brief = post.Md
} else {
post.Brief = string([]rune(post.Md)[:config.Data.Posts.BriefMaxLen])
}
} }
} }

@ -24,7 +24,7 @@ export const TextStoryCard= (props:Props) =>{
return ( return (
//@ts-ignore //@ts-ignore
<Lay justifyContent="space-between" alignItems={isSmallScreen? "left" : "center"} {...rest}> <Lay justifyContent="space-between" alignItems={isSmallScreen? "left" : "center"} {...rest}>
<VStack alignItems="left" as="a" href={story.url ?? getStoryUrl(story)} spacing={{base: 4, md: 2}}> <VStack alignItems="left" as="a" href={getStoryUrl(story)} spacing={{base: 4, md: 2}}>
<Heading size="sm" display="flex" alignItems="center"> <Heading size="sm" display="flex" alignItems="center">
{showSource && <> {story.url ? <Tag size="sm" mr="2"></Tag> : <Tag size="sm" mr="2"></Tag>}</>} {showSource && <> {story.url ? <Tag size="sm" mr="2"></Tag> : <Tag size="sm" mr="2"></Tag>}</>}
{story.title ?story.title : 'No Title'} {story.title ?story.title : 'No Title'}

Loading…
Cancel
Save