Skip to content

Commit

Permalink
fix: subreddit id bug
Browse files Browse the repository at this point in the history
  • Loading branch information
AdhamAliAbdelAal committed Dec 3, 2022
1 parent 6a21b51 commit 725af4e
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 32 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,7 @@ module.exports = {
'no-shadow': 'off',
// disabling no await in loop
'no-await-in-loop': 'off',
// disabling no-underscore-dangle
'no-underscore-dangle': 'off',
},
};
2 changes: 1 addition & 1 deletion data/homePagePosts.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion devops/jenkins/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ HOST=0.0.0.0
REACT_APP_GOOGLECLIENTID=\'"$GOOGLE_APP_ID"\'
REACT_APP_FACEBOOKCLIENTID=\'"$FACEBOOK_APP_ID"\'
REACT_APP_SITEKEY="6LdjH-kiAAAAANFbV6SUnCjXNK3Z0h7q7j4IFf7i"
REACT_APP_ENV='production'
REACT_APP_ENV='development'
REACT_APP_PROXY_DEVELOPMENT="http://localhost:8000"
REACT_APP_PROXY_PRODUCTION="https://api.nonlegit.click/api/v1"' > .env
# Build the docker image
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {

import { useState, useEffect } from 'react';

import { useParams } from 'react-router-dom';
import { useNavigate, useParams } from 'react-router-dom';
import {
FormContainer, Title, TitleContainer, DraftsButton, Badge, CustomDivider, PostFormContainer, FieldsContainer, PostTitle, PostText, PostUrl, WordCounter,
} from './styles';
Expand All @@ -28,6 +28,7 @@ import currentSubredditServer from './currentSubredditServer';
function CreatePostForm() {
// routes
const { subredditName } = useParams();
const navigate = useNavigate();
console.log(subredditName);

// server
Expand All @@ -52,6 +53,8 @@ function CreatePostForm() {
const [spoiler, setSpoiler] = useState(false);
const [nswf, setNswf] = useState(false);
const [sendReplies, setSendReplies] = useState(true);
console.log('title', title);
console.log('community to post in', communityToPostIn);

useEffect(() => {
setCommunityToPostIn(subredditId);
Expand Down Expand Up @@ -81,7 +84,7 @@ function CreatePostForm() {
sendReplies,
};
console.log(post);
submitPostServer(post);
submitPostServer(post, navigate);
};
/**
* This function handles title change
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import axios from '../../../../services/instance';
* @function submitPostServer
* @param {Object} post - post to be posted
*/
const submitPostServer = (post) => {
const submitPostServer = (post, navigate) => {
console.log(JSON.stringify(post));
axios.post('/posts', JSON.stringify(post)).then((response) => {
console.log(response.data);
Expand All @@ -14,7 +14,7 @@ const submitPostServer = (post) => {
const { message } = response.data;
console.log(message);
} else {
// post created successfully
navigate('/');
}
alert('posted successfully');
}).catch((e) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const createPostServer = () => {
const communitiesUrl = '/subreddits/mine/subscriber';
const [data, communitiesError, statusCode] = useFetch(communitiesUrl);
const communities = data?.data.map((community) => ({
...community, subredditName: community.fixedName,
...community, subredditName: community.fixedName, id: community._id,
}));
console.log('communities', communities);
console.log(statusCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function PostList(props) {
<>
{posts.map((post) => {
const {
_id: id, createdAt, title, images, ownerName, ownerIcon, authorName, flairText, flairBackgroundColor, flairColor, kind, votes, commentCount, text, videos,
_id: id, createdAt, title, images, ownerName, ownerIcon, authorName, flairText, flairBackgroundColor, flairColor, kind, votes, commentCount, text, videos, ownerType,
} = post;
return (
<Post
Expand All @@ -32,6 +32,7 @@ function PostList(props) {
commentCount={commentCount}
text={text}
key={id}
ownerType={ownerType}
/>
);
})}
Expand Down
6 changes: 3 additions & 3 deletions src/components/HomePage/HomePageContainer/homePageServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ const homePageServer = (postClass) => {
// for backend bugs
const temp = {
_id: 1,
text: 'اي كلام/r/all',
backgroundColor: '#ea0027',
textColor: '#fff',
text: '',
backgroundColor: '',
textColor: '',
};
const {
text: flairText,
Expand Down
6 changes: 4 additions & 2 deletions src/components/Post/Post.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import PostHeader from './PostHeader/PostHeader';
*
* @component Post
* @property {string} title -Post title.
* @property {string} ownerType -Post owner type user or subreddit.
* @property {string} ownerIcon -Post owner icon.
* @property {string} ownerName -Post subreddit(post owner).
* @property {string} authorName -Post author.
Expand All @@ -35,7 +36,7 @@ import PostHeader from './PostHeader/PostHeader';

function Post(props) {
const {
createdAt, title, images, ownerName, ownerIcon, authorName, flairText, flairBackgroundColor, flairColor, kind, votes, commentCount, text, videos,
createdAt, title, images, ownerType, ownerName, ownerIcon, authorName, flairText, flairBackgroundColor, flairColor, kind, votes, commentCount, text, videos,
subredit,
} = props;
const theme = useTheme();
Expand All @@ -57,11 +58,12 @@ function Post(props) {
ownerIcon={ownerIcon}
ownerName={ownerName}
authorName={authorName}
flair={flairText}
flairText={flairText}
flairBackgroundColor={flairBackgroundColor}
flairColor={flairColor}
createdAt={createdAt}
subredit={subredit}
ownerType={ownerType}
/>
<PostMedia mt={1.5} kind={kind}>
{/* eslint-disable jsx-a11y/media-has-caption */}
Expand Down
47 changes: 28 additions & 19 deletions src/components/Post/PostHeader/PostHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
*
* @component PostHeader
* @property {string} title -Post title.
* @property {string} ownerType -Post owner type user or subreddit.
* @property {string} ownerIcon -Post ownerName icon.
* @property {string} ownerName -Post subreddit(post ownerName).
* @property {string} authorName -Post authorName.
Expand All @@ -28,7 +29,7 @@ import {

function PostHeader(props) {
const {
title, ownerIcon, ownerName, authorName, flair, flairBackgroundColor, flairColor, createdAt,
title, ownerIcon, ownerType, ownerName, authorName, flairText, flairBackgroundColor, flairColor, createdAt,
subredit,

} = props;
Expand All @@ -48,27 +49,30 @@ function PostHeader(props) {
/>

<PostInfoLink to={`/Subreddit/${ownerName}`} color="#000" fontWeight="bolder">
r/
{ownerType === 'Subreddit' ? 'r/' : 'u/'}
{ownerName}
</PostInfoLink>
</>
)}
<Box color="#787C7E" fontWeight={300} display="flex" gap="4px" flexWrap="wrap">
{!subredit && (
<span>
</span>
{ownerType === 'Subreddit' && (
<>
{!subredit && (
<span>
</span>
)}
<div>Posted By</div>
<PostInfoLink to={`/user/${authorName}`} color="inherit" fontWeight="normal">
u/
{authorName}
</PostInfoLink>
</>
)}
<div>Posted By</div>
<PostInfoLink to={`/user/${authorName}`} color="inherit" fontWeight="normal">
u/
{authorName}
</PostInfoLink>

<CreatedAt color="inherit" fontWeight="normal">
{calculateTime(createdAt)}
</CreatedAt>

</Box>
{!subredit && (
<Box display="flex" justifyContent="flex-end" flexGrow={1} alignItems="flex-start">
Expand All @@ -84,13 +88,18 @@ function PostHeader(props) {
>
{title}
{' '}
<Flair
disableRipple
backgroundColor={flairBackgroundColor}
flairColor={flairColor}
>
{flair}
</Flair>
{
flairText
&& (
<Flair
disableRipple
backgroundColor={flairBackgroundColor}
flairColor={flairColor}
>
{flairText}
</Flair>
)
}
</Typography>
</PostTitle>
</>
Expand Down

0 comments on commit 725af4e

Please sign in to comment.