Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

fix image posts not displaying their images #11

Merged
merged 1 commit into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions frontend/src/components/ImagePost.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Button from '@mui/material/Button'
import axios from 'axios';
import { ServerUrlContext } from '../context/ServerUrlContext';

const ImagePost = ({title, body, datePosted, imageKey, previewImage, liked, publicId, postId, dispatch, userId, previewMode}) => {
const ImagePost = ({title, body, datePosted, image, previewImage, liked, publicId, postId, dispatch, userId, previewMode}) => {
const {darkMode, setDarkMode} = useContext(DarkModeContext)
const changingLikeStatus = useRef(false)
const deleting = useRef(false)
Expand Down Expand Up @@ -66,7 +66,7 @@ const ImagePost = ({title, body, datePosted, imageKey, previewImage, liked, publ
<div style={{border: `1px solid ${darkMode ? 'white' : 'black'}`, maxHeight: '100%'}}>
<h1 style={{wordBreak: 'break-all'}}>{title}</h1>
<p style={{wordBreak: 'break-all'}}>{body}</p>
<img src={previewImage ? previewImage : `${serverUrl}/image/${imageKey}`} style={{maxHeight: '100%', maxWidth: '100%'}}/>
<img src={previewImage ? previewImage : image} style={{maxHeight: '100%', maxWidth: '100%'}}/>
<br/>
<FontAwesomeIcon
icon={liked ? fasHeart : farHeart}
Expand Down
12 changes: 9 additions & 3 deletions frontend/src/routes/Profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,16 @@ const Profile = () => {

axios.get(`${serverUrl}/user/imagePostsByUserName/?username=${name}&skip=${Array.isArray(imagePostState.posts) ? imagePostState.posts.length : 0}&publicId=${publicId}`)
.then(response => response.data.data)
.then(result => {
.then(async (result) => {
const posts = []
for (const post of result) {
const imageData = (await axios.get(`${serverUrl}/image/${post.imageKey}`)).data
post.image = 'data:image/jpeg;base64,' + imageData
posts.push(post)
}
dispatchImagePostUpdate({
type: 'addPosts',
result
result: posts
})
}).catch(error => {
dispatchImagePostUpdate({
Expand Down Expand Up @@ -249,7 +255,7 @@ const Profile = () => {
const DisplayTextPosts = useMemo(() => {
return Array.isArray(textPostState.posts) ? textPostState.posts.map((post, index) => (
<Fragment key={index.toString()}>
<TextPost {...post} publicId={publicId} dispatch={dispatchTextPostUpdate} userId={_id}/>
<TextPost {...post} publicId={publicId} dispatch={dispatchTextPostUpdate} userId={_id} profileName={name} profileImage={profileImageUri}/>
</Fragment>
)) : null
}, [textPostState.posts, textPostState.reRenderTimes])
Expand Down