diff --git a/backend/src/db/api/posts.js b/backend/src/db/api/posts.js index f4ef2d6..a66bd49 100644 --- a/backend/src/db/api/posts.js +++ b/backend/src/db/api/posts.js @@ -1,4 +1,3 @@ - const db = require('../models'); const FileDBApi = require('./file'); const crypto = require('crypto'); @@ -487,6 +486,7 @@ module.exports = class PostsDBApi { output.author = await posts.getAuthor({ + include: [{ model: db.file, as: 'avatar' }], transaction }); @@ -529,7 +529,7 @@ module.exports = class PostsDBApi { { model: db.users, as: 'author', - + include: [{ model: db.file, as: 'avatar' }], where: filter.author ? { [Op.or]: [ { id: { [Op.in]: filter.author.split('|').map(term => Utils.uuid(term)) } }, @@ -899,5 +899,4 @@ module.exports = class PostsDBApi { } -}; - +}; \ No newline at end of file diff --git a/frontend/src/components/Socio/CreatePost.tsx b/frontend/src/components/Socio/CreatePost.tsx new file mode 100644 index 0000000..1d7ee8b --- /dev/null +++ b/frontend/src/components/Socio/CreatePost.tsx @@ -0,0 +1,75 @@ +import React, { useState } from 'react'; +import { mdiImageOutline, mdiVideoOutline, mdiEmoticonOutline, mdiSend } from '@mdi/js'; +import BaseIcon from '../BaseIcon'; +import UserAvatarCurrentUser from '../UserAvatarCurrentUser'; +import { useAppDispatch } from '../../stores/hooks'; +import { create as createPost } from '../../stores/posts/postsSlice'; +import BaseButton from '../BaseButton'; + +const CreatePost = ({ onPostCreated }: { onPostCreated: () => void }) => { + const dispatch = useAppDispatch(); + const [caption, setCaption] = useState(''); + const [loading, setLoading] = useState(false); + + const handleSubmit = async () => { + if (!caption.trim()) return; + + setLoading(true); + try { + await dispatch(createPost({ + caption, + post_type: 'text', + visibility: 'public', + published_at: new Date().toISOString() + })); + setCaption(''); + onPostCreated(); + } catch (error) { + console.error('Failed to create post', error); + } finally { + setLoading(false); + } + }; + + return ( +
+
+ +
+