Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[no-jira] Add "Newer" and "Older" navigation to Posts page #53

Merged
merged 3 commits into from
Feb 26, 2024
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: 4 additions & 0 deletions src/helpers/permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export const isAdmin = (userRoles) => {
return userRoles.includes(ADMIN);
};

export const isCoach = (user) => {
return getUserType(user) === "coach";
};

function isPostModerator({ user, communityUser, post }) {
const hasModeratorPermissions =
isAdmin(user.roles) || isModerator(user.roles) || isModerator(communityUser.roles);
Expand Down
1 change: 1 addition & 0 deletions src/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"post.myTimeline": "Meine Zeitachse",
"post.wasLive": "war live",
"post.copyPath": "Pfad kopieren",
"post.openInNewTab": "Open in new tab",

"post.success.approved": "Beitrag genehmigt",
"post.success.declined": "Beitrag abgelehnt",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"post.myTimeline": "My Timeline",
"post.wasLive": "was live",
"post.copyPath": "Copy path",
"post.openInNewTab": "Open in new tab",

"post.success.approved": "Post approved",
"post.success.declined": "Post declined",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"post.myTimeline": "Mi Línea del tiempo",
"post.wasLive": "estuvo en vivo",
"post.copyPath": "Copiar camino",
"post.openInNewTab": "Open in new tab",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does not look spanish :D

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coach ops told me I can leave anything that's only coach facing in English, so I made this coach facing only even if it would be useful for users, just so I wouldn't have to translate it :D


"post.success.approved": "Publicación aprobada",
"post.success.declined": "Publicación rechazada",
Expand Down
14 changes: 13 additions & 1 deletion src/social/components/post/Post/DefaultPostRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Modal from '~/core/components/Modal';
import { notification } from '~/core/components/Notification';
import { useAsyncCallback } from '~/core/hooks/useAsyncCallback';
import useUser from '~/core/hooks/useUser';
import { canDeletePost, canEditPost, canReportPost, canClosePool, canPerformUserLookups, canPerformStingActions } from '~/helpers/permissions';
import { isCoach, canDeletePost, canEditPost, canReportPost, canClosePool, canPerformUserLookups, canPerformStingActions } from '~/helpers/permissions';
import { isPostUnderReview } from '~/helpers/utils';
import EngagementBar from '~/social/components/EngagementBar';
import ChildrenContent from '~/social/components/post/ChildrenContent';
Expand Down Expand Up @@ -151,6 +151,14 @@ const DefaultPostRenderer = ({
handleCopyPostPath(post);
};

const onOpenInNewTab = () => {
const pathToContent = post.path.replace(
/.+\/social\//,
`${window.location.protocol}//${window.location.hostname}/`,
);
window.open(pathToContent, '_blank');
};

const onLookupUser = () => {
window.open(`${manateeUrl}/user/${post.postedUserId}`, '_blank');
};
Expand Down Expand Up @@ -220,6 +228,10 @@ const DefaultPostRenderer = ({
name: 'post.copyPath',
action: onCopyPathClick,
},
isCoach(currentUser) && {
name: 'post.openInNewTab',
action: onOpenInNewTab,
},
canPerformUserLookups({
actingUserType: currentUserType,
targetUserType: postUserType,
Expand Down
53 changes: 51 additions & 2 deletions src/social/pages/CommunityPost/index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,73 @@
import React from 'react';
import React, { useState } from 'react';
import PropTypes from 'prop-types';
import { useNavigate } from 'react-router-dom';

import { PrimaryButton } from '~/core/components/Button';
import useUser from '~/core/hooks/useUser';
import { isCoach } from '~/helpers/permissions';
import withSDK from '~/core/hocs/withSDK';
import CommunityInfo from '~/social/components/CommunityInfo';
import Post from '~/social/components/post/Post';
import { useConfig } from '~/social/providers/ConfigProvider';

import { Wrapper } from './styles';
import { Wrapper, NavButtonGroup } from './styles';

const CommunityPost = ({
currentUserId,
postId,
commentId,
communityId,
readonly,
handleCopyPostPath,
handleCopyCommentPath,
}) => {
const { fetchNextPostInCommunity } = useConfig();
const { user: currentUser } = useUser(currentUserId, [currentUserId]);
const [olderButtonDisabled, setOlderButtonDisabled] = useState(false);
const [newerButtonDisabled, setNewerButtonDisabled] = useState(false);
const navigate = useNavigate();

const onOlderPost = async (communityId, postId) => {
const nextPostPath = await fetchNextPostInCommunity(communityId, postId, "AFTER");
if (nextPostPath) {
navigate(nextPostPath);
setNewerButtonDisabled(false);
} else {
setOlderButtonDisabled(true);
}
};
const onNewerPost = async () => {
const nextPostPath = await fetchNextPostInCommunity(communityId, postId, "BEFORE");
if (nextPostPath) {
navigate(nextPostPath);
setOlderButtonDisabled(false);
} else {
setNewerButtonDisabled(true);
}
};

return (
<Wrapper>
<CommunityInfo communityId={communityId} />

{
isCoach(currentUser) &&
<NavButtonGroup isFullWidth>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Add some margin to the bottom and adjust ButtonGroup spacing so it matches the spacing with the top card.

<PrimaryButton
disabled={olderButtonDisabled}
onClick={() => onOlderPost(communityId, postId)}
>
&lt; Older
</PrimaryButton>
<PrimaryButton
disabled={newerButtonDisabled}
onClick={() => onNewerPost(communityId, postId)}
>
Newer &gt;
</PrimaryButton>
</NavButtonGroup>
}

<Post
key={postId}
postId={postId}
Expand Down
5 changes: 5 additions & 0 deletions src/social/pages/CommunityPost/styles.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import styled from 'styled-components';
import { ButtonGroup } from '~/core/components/Button';

export const Wrapper = styled.div`
height: 100%;
max-width: 695px;
overflow-y: auto;
`;

export const NavButtonGroup = styled(ButtonGroup)`
margin-bottom: 12px;
`;
6 changes: 6 additions & 0 deletions src/social/providers/ConfigProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export type SocialConfiguration = {
userLocale: string,
optionalMessage?: string,
) => Promise<boolean>;
fetchNextPostInCommunity: (
communityId: string,
postId: string,
direction: string,
) => Promise<string | undefined>;
};

const defaultConfig = {
Expand All @@ -32,6 +37,7 @@ const defaultConfig = {
addCoachNoteCallback: async (_uac: string, _userLocale: string, _note: string) => false,
transferUserToStingCallback: async (_uac: string, _userLocale: string, _message?: string) =>
false,
fetchNextPostInCommunity: async (_cid: string, _pid: string, _dir: string) => '',
};

const ConfigContext = createContext(defaultConfig);
Expand Down
Loading