Skip to content

Commit

Permalink
feat(fe-piattaforma): fe updates 10272022
Browse files Browse the repository at this point in the history
  • Loading branch information
Niccolo Valente committed Oct 27, 2022
1 parent 1849eba commit 79b19b3
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 49 deletions.
73 changes: 38 additions & 35 deletions fe-piattaforma/src/components/Comments/answersSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ interface AnswerSectionI {
}

const AnswersSection: React.FC<AnswerSectionI> = (props) => {
const { thread, showReplies, replies } = props;
const { thread, showReplies, replies = [] } = props;
const device = useAppSelector(selectDevice);

const dispatch = useDispatch();

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
if (replies === '[]') return null;

return (
<div>
{showReplies && (
Expand All @@ -31,40 +35,39 @@ const AnswersSection: React.FC<AnswerSectionI> = (props) => {
thread && !device.mediaIsPhone && 'comment-container__thread'
)}
>
{replies &&
replies.map((comment, index: number) => (
<CommentAnswer
key={index}
{...comment}
noBorder={replies.length > 1 && index < replies.length - 1}
onDeleteComment={() =>
dispatch(
openModal({
id: 'delete-forum-entity',
payload: {
text: 'Confermi di voler eliminare questo contenuto?',
entity: 'comment',
id: comment.id,
author: comment.author
},
})
)
}
onEditComment={() =>
dispatch(
openModal({
id: 'comment-modal',
payload: {
title: 'Modifica commento',
action: 'edit',
id: comment.id,
body: comment.body,
},
})
)
}
/>
))}
{(replies || []).map((comment, index: number) => (
<CommentAnswer
key={index}
{...comment}
noBorder={replies.length > 1 && index < replies.length - 1}
onDeleteComment={() =>
dispatch(
openModal({
id: 'delete-forum-entity',
payload: {
text: 'Confermi di voler eliminare questo contenuto?',
entity: 'comment',
id: comment.id,
author: comment.author,
},
})
)
}
onEditComment={() =>
dispatch(
openModal({
id: 'comment-modal',
payload: {
title: 'Modifica commento',
action: 'edit',
id: comment.id,
body: comment.body,
},
})
)
}
/>
))}
</div>
)}
</div>
Expand Down
14 changes: 11 additions & 3 deletions fe-piattaforma/src/components/Comments/comment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const Comment: React.FC<CommentI> = (props) => {
date,
author,
section,
replies,
replies = [],
likes,
user_like,
views,
Expand Down Expand Up @@ -322,10 +322,18 @@ const Comment: React.FC<CommentI> = (props) => {
<div style={{ width: '94%' }}>{body}</div>
<div className='comment-container__border mt-4 mb-2'></div>
<SocialBar
replies={section === 'community' ? replies.length : undefined}
replies={
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
section === 'community' && replies !== '[]'
? replies?.length
: undefined
}
views={section === 'community' ? views : undefined}
onShowReplies={
section === 'community' && replies.length
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
section === 'community' && replies !== '[]' && replies?.length
? () => setShowReplies((prev) => !prev)
: undefined
}
Expand Down
2 changes: 1 addition & 1 deletion fe-piattaforma/src/components/Comments/commentSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const CommentSection: React.FC<commentSectionI> = ({ section }) => {
</div>
{comments.map((comment, i) => (
<Comment
key={comment.id}
key={`${comment.id}-${comment.body}`}
section={section}
thread={comments.length > 1 && i < comments.length - 1}
{...comment}
Expand Down
12 changes: 8 additions & 4 deletions fe-piattaforma/src/components/Comments/socialBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const SocialBar: React.FC<SocialI> = (props) => {

const device = useAppSelector(selectDevice);

console.log('replies', replies)

return (
<div
className={clsx(
Expand Down Expand Up @@ -175,10 +177,12 @@ const SocialBar: React.FC<SocialI> = (props) => {
>
{`${showReplies ? 'NASCONDI RISPOSTE' : 'MOSTRA RISPOSTE'}`}
</p>
<span
className='primary-color pl-1 letter-spacing'
style={{ fontWeight: 400 }}
>{`(${replies})`}</span>
{replies ? (
<span
className='primary-color pl-1 letter-spacing'
style={{ fontWeight: 400 }}
>{`(${replies})`}</span>
) : null}
</div>
</Button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,12 @@ const ManageComment: React.FC<ManageCommentI> = ({
}
}
};

return (
<GenericModal
id={modalId}
primaryCTA={{
disabled: newComment.trim() === '',
disabled: newComment?.toString()?.trim() === '',
label: creation ? 'Conferma' : 'Salva',
onClick: handleSaveComment,
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const ManageDocument: React.FC<ManageDocumentI> = ({
id,
{
...newFormValues,
title: newFormValues.title?.toString(),
program_label:
newFormValues.program === 'public'
? 'Tutti i programmi'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ const ManageNews: React.FC<ManageNewsI> = ({
id,
{
...newFormValues,
title: newFormValues.title?.toString(),
program_label:
newFormValues.program === 'public'
? 'Tutti i programmi'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const ManageTopic: React.FC<ManageTopicI> = ({
id,
{
...newFormValues,
title: newFormValues.title?.toString(),
entity:
userProfile?.idProgetto || userProfile?.idProgramma
? userProfile.nomeEnte
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const GetCommentsList =
);
// const res = await API.get(`/item/${itemId}/comments/user/${userId}`)
if (res) {
dispatch(setCommentsList(res.data.data.items || []));
dispatch(setCommentsList(res.data?.data?.items || []));
}
} catch (error) {
console.log('GetCommentsList error', error);
Expand All @@ -36,10 +36,12 @@ export const CreateComment =
try {
dispatch(showLoader());
dispatch({ ...CreateCommentAction });
const res = await proxyCall(`/item/${itemId}/comment`, 'POST', {
comment_body: comment,
});
return res;
if (comment) {
const res = await proxyCall(`/item/${itemId}/comment`, 'POST', {
comment_body: comment?.toString(),
});
return res;
}
} catch (error) {
console.log('CreateComment error', error);
return false;
Expand Down

0 comments on commit 79b19b3

Please sign in to comment.