From 5ec6cacb69623513244df50aa92b0047c4694675 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 11 Feb 2024 23:33:35 +0800 Subject: [PATCH] :bug: Fix won't add attachment --- .../src/components/posts/PostEditActions.tsx | 43 +++++++++++++------ 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/pkg/view/src/components/posts/PostEditActions.tsx b/pkg/view/src/components/posts/PostEditActions.tsx index c914073..69c8e3e 100644 --- a/pkg/view/src/components/posts/PostEditActions.tsx +++ b/pkg/view/src/components/posts/PostEditActions.tsx @@ -13,7 +13,7 @@ export default function PostEditActions(props: { onInputTags: (tags: any[]) => void, onError: (message: string | null) => void, }) { - const userinfo = useUserinfo() + const userinfo = useUserinfo(); const [uploading, setUploading] = createSignal(false); @@ -57,10 +57,17 @@ export default function PostEditActions(props: { ...data, author_id: userinfo?.profiles?.id }])); - props.onInputCategories(categories()) + props.onInputAttachments(attachments()); form.reset(); } + function removeAttachment(idx: number) { + const data = attachments().slice(); + data.splice(idx, 1); + setAttachments(data); + props.onInputAttachments(attachments()); + } + function addCategory(evt: SubmitEvent) { evt.preventDefault(); @@ -70,12 +77,15 @@ export default function PostEditActions(props: { if (!data.name) return; setCategories(categories().concat([data as any])); - props.onInputCategories(categories()) + props.onInputCategories(categories()); form.reset(); } - function removeCategory(target: any) { - setCategories(categories().filter(item => item.alias !== target.alias)); + function removeCategory(idx: number) { + const data = categories().slice(); + data.splice(idx, 1); + setCategories(data); + props.onInputCategories(categories()); } function addTag(evt: SubmitEvent) { @@ -87,13 +97,15 @@ export default function PostEditActions(props: { if (!data.name) return; setTags(tags().concat([data as any])); - props.onInputTags(tags()) + props.onInputTags(tags()); form.reset(); } - function removeTag(target: any) { - setTags(tags().filter(item => item.alias !== target.alias)); - props.onInputTags(tags()) + function removeTag(idx: number) { + const data = tags().slice(); + data.splice(idx, 1); + setTags(data); + props.onInputTags(tags()); } return ( @@ -227,9 +239,12 @@ export default function PostEditActions(props: {

Attachment list

    - {item =>
  1. + {(item, idx) =>
  2. {item.filename} +
  3. }
@@ -269,10 +284,10 @@ export default function PostEditActions(props: {

Category list

    - {item =>
  1. + {(item, idx) =>
  2. {item.name} #{item.alias} -
  3. } @@ -305,10 +320,10 @@ export default function PostEditActions(props: {

    Category list

      - {item =>
    1. + {(item, idx) =>
    2. {item.name} #{item.alias} -
    3. }