diff --git a/client/components/social/PostComposer.tsx b/client/components/social/PostComposer.tsx index 90e9c4b6..baf5290d 100644 --- a/client/components/social/PostComposer.tsx +++ b/client/components/social/PostComposer.tsx @@ -17,18 +17,26 @@ function readFileAsDataURL(file: File): Promise { }); } -export default function PostComposer({ onPosted }: { onPosted?: () => void }) { +export default function PostComposer({ + onPosted, + suggestedTags = [], +}: { + onPosted?: () => void; + suggestedTags?: string[]; +}) { const { user } = useAuth(); const { toast } = useToast(); const [text, setText] = useState(""); const [mediaFile, setMediaFile] = useState(null); const [mediaUrlInput, setMediaUrlInput] = useState(""); const [submitting, setSubmitting] = useState(false); + const [selectedTags, setSelectedTags] = useState([]); const reset = () => { setText(""); setMediaFile(null); setMediaUrlInput(""); + setSelectedTags([]); }; const uploadToStorage = async (file: File): Promise => { @@ -104,12 +112,18 @@ export default function PostComposer({ onPosted }: { onPosted?: () => void }) { ? "New photo" : "Update"); + const inlineTags = Array.from((text.match(/#[\p{L}0-9_]+/gu) || []).map((t) => t.replace(/^#/, "").toLowerCase())); + const baseTags = mediaType === "none" ? ["update"] : [mediaType, "feed"]; + const combinedTags = Array.from( + new Set([...baseTags, ...selectedTags.map((t) => t.toLowerCase()), ...inlineTags]).values(), + ); + await communityService.createPost({ author_id: user.id, title, content, category: mediaType === "none" ? "text" : mediaType, - tags: mediaType === "none" ? ["update"] : [mediaType, "feed"], + tags: combinedTags, is_published: true, } as any); @@ -131,11 +145,36 @@ export default function PostComposer({ onPosted }: { onPosted?: () => void }) {