-
-
Notifications
You must be signed in to change notification settings - Fork 864
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
Updated user post screen UI #2046
Changes from 2 commits
3915e17
672397d
4db7c23
e75d9c6
5d5b790
cfbd465
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,16 +1,15 @@ | ||||||||||||||||||||||||||||||
import { useQuery } from '@apollo/client'; | ||||||||||||||||||||||||||||||
import HourglassBottomIcon from '@mui/icons-material/HourglassBottom'; | ||||||||||||||||||||||||||||||
import SendIcon from '@mui/icons-material/Send'; | ||||||||||||||||||||||||||||||
import ChevronRightIcon from '@mui/icons-material/ChevronRight'; | ||||||||||||||||||||||||||||||
import ChevronLeftIcon from '@mui/icons-material/ChevronLeft'; | ||||||||||||||||||||||||||||||
import { | ||||||||||||||||||||||||||||||
ADVERTISEMENTS_GET, | ||||||||||||||||||||||||||||||
ORGANIZATION_ADVERTISEMENT_LIST, | ||||||||||||||||||||||||||||||
ORGANIZATION_POST_LIST, | ||||||||||||||||||||||||||||||
USER_DETAILS, | ||||||||||||||||||||||||||||||
} from 'GraphQl/Queries/Queries'; | ||||||||||||||||||||||||||||||
import PostCard from 'components/UserPortal/PostCard/PostCard'; | ||||||||||||||||||||||||||||||
import type { | ||||||||||||||||||||||||||||||
InterfacePostCard, | ||||||||||||||||||||||||||||||
InterfaceQueryOrganizationAdvertisementListItem, | ||||||||||||||||||||||||||||||
InterfaceQueryUserListItem, | ||||||||||||||||||||||||||||||
} from 'utils/interfaces'; | ||||||||||||||||||||||||||||||
import PromotedPost from 'components/UserPortal/PromotedPost/PromotedPost'; | ||||||||||||||||||||||||||||||
|
@@ -23,7 +22,36 @@ import { Navigate, useParams } from 'react-router-dom'; | |||||||||||||||||||||||||||||
import useLocalStorage from 'utils/useLocalstorage'; | ||||||||||||||||||||||||||||||
import styles from './Posts.module.css'; | ||||||||||||||||||||||||||||||
import convertToBase64 from 'utils/convertToBase64'; | ||||||||||||||||||||||||||||||
import Carousel from 'react-multi-carousel'; | ||||||||||||||||||||||||||||||
import 'react-multi-carousel/lib/styles.css'; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
const responsive = { | ||||||||||||||||||||||||||||||
superLargeDesktop: { | ||||||||||||||||||||||||||||||
breakpoint: { max: 4000, min: 3000 }, | ||||||||||||||||||||||||||||||
items: 5, | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
desktop: { | ||||||||||||||||||||||||||||||
breakpoint: { max: 3000, min: 1024 }, | ||||||||||||||||||||||||||||||
items: 3, | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
tablet: { | ||||||||||||||||||||||||||||||
breakpoint: { max: 1024, min: 600 }, | ||||||||||||||||||||||||||||||
items: 2, | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
mobile: { | ||||||||||||||||||||||||||||||
breakpoint: { max: 600, min: 0 }, | ||||||||||||||||||||||||||||||
items: 1, | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
type Ad = { | ||||||||||||||||||||||||||||||
_id: string; | ||||||||||||||||||||||||||||||
name: string; | ||||||||||||||||||||||||||||||
type: 'BANNER' | 'MENU' | 'POPUP'; | ||||||||||||||||||||||||||||||
mediaUrl: string; | ||||||||||||||||||||||||||||||
endDate: string; // Assuming it's a string in the format 'yyyy-MM-dd' | ||||||||||||||||||||||||||||||
startDate: string; // Assuming it's a string in the format 'yyyy-MM-dd' | ||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||
interface InterfaceAdContent { | ||||||||||||||||||||||||||||||
_id: string; | ||||||||||||||||||||||||||||||
name: string; | ||||||||||||||||||||||||||||||
|
@@ -45,10 +73,6 @@ type AdvertisementsConnection = { | |||||||||||||||||||||||||||||
}[]; | ||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
interface InterfaceAdConnection { | ||||||||||||||||||||||||||||||
advertisementsConnection?: AdvertisementsConnection; | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
type InterfacePostComments = { | ||||||||||||||||||||||||||||||
creator: { | ||||||||||||||||||||||||||||||
_id: string; | ||||||||||||||||||||||||||||||
|
@@ -101,8 +125,7 @@ export default function home(): JSX.Element { | |||||||||||||||||||||||||||||
const { getItem } = useLocalStorage(); | ||||||||||||||||||||||||||||||
const [posts, setPosts] = useState([]); | ||||||||||||||||||||||||||||||
const [pinnedPosts, setPinnedPosts] = useState([]); | ||||||||||||||||||||||||||||||
const [adContent, setAdContent] = useState<InterfaceAdConnection>({}); | ||||||||||||||||||||||||||||||
const [filteredAd, setFilteredAd] = useState<InterfaceAdContent[]>([]); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
const [showModal, setShowModal] = useState<boolean>(false); | ||||||||||||||||||||||||||||||
const [postImg, setPostImg] = useState<string | null>(''); | ||||||||||||||||||||||||||||||
const { orgId } = useParams(); | ||||||||||||||||||||||||||||||
|
@@ -111,17 +134,32 @@ export default function home(): JSX.Element { | |||||||||||||||||||||||||||||
return <Navigate to={'/user'} />; | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
const navbarProps = { | ||||||||||||||||||||||||||||||
currentPage: 'home', | ||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||
const { data: promotedPostsData } = useQuery(ADVERTISEMENTS_GET); | ||||||||||||||||||||||||||||||
const { | ||||||||||||||||||||||||||||||
data: promotedPostsData, | ||||||||||||||||||||||||||||||
}: { | ||||||||||||||||||||||||||||||
data?: { | ||||||||||||||||||||||||||||||
organizations: InterfaceQueryOrganizationAdvertisementListItem[]; | ||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||
refetch: () => void; | ||||||||||||||||||||||||||||||
} = useQuery(ORGANIZATION_ADVERTISEMENT_LIST, { | ||||||||||||||||||||||||||||||
variables: { | ||||||||||||||||||||||||||||||
id: orgId, | ||||||||||||||||||||||||||||||
first: 6, | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||
const { | ||||||||||||||||||||||||||||||
data, | ||||||||||||||||||||||||||||||
refetch, | ||||||||||||||||||||||||||||||
loading: loadingPosts, | ||||||||||||||||||||||||||||||
} = useQuery(ORGANIZATION_POST_LIST, { | ||||||||||||||||||||||||||||||
variables: { id: orgId, first: 10 }, | ||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
const [adContent, setAdContent] = useState( | ||||||||||||||||||||||||||||||
promotedPostsData?.organizations[0].advertisements?.edges.map( | ||||||||||||||||||||||||||||||
(edge: { node: Ad }) => edge.node, | ||||||||||||||||||||||||||||||
) || [], | ||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||
const userId: string | null = getItem('userId'); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
const { data: userData } = useQuery(USER_DETAILS, { | ||||||||||||||||||||||||||||||
|
@@ -137,15 +175,16 @@ export default function home(): JSX.Element { | |||||||||||||||||||||||||||||
}, [data]); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
useEffect(() => { | ||||||||||||||||||||||||||||||
if (promotedPostsData) { | ||||||||||||||||||||||||||||||
setAdContent(promotedPostsData); | ||||||||||||||||||||||||||||||
if (promotedPostsData && promotedPostsData.organizations) { | ||||||||||||||||||||||||||||||
const ads: Ad[] = | ||||||||||||||||||||||||||||||
promotedPostsData.organizations[0].advertisements?.edges.map( | ||||||||||||||||||||||||||||||
(edge) => edge.node, | ||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
setAdContent(ads); | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The use of optional chaining here can prevent potential runtime errors when - const ads: Ad[] = promotedPostsData.organizations[0].advertisements?.edges.map((edge) => edge.node);
+ const ads: Ad[] = promotedPostsData?.organizations[0]?.advertisements?.edges.map((edge) => edge.node) || []; Committable suggestion
Suggested change
ToolsBiome
|
||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
}, [promotedPostsData]); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
useEffect(() => { | ||||||||||||||||||||||||||||||
setFilteredAd(filterAdContent(adContent, orgId)); | ||||||||||||||||||||||||||||||
}, [adContent]); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
useEffect(() => { | ||||||||||||||||||||||||||||||
setPinnedPosts( | ||||||||||||||||||||||||||||||
posts.filter(({ node }: { node: InterfacePostNode }) => { | ||||||||||||||||||||||||||||||
|
@@ -154,34 +193,6 @@ export default function home(): JSX.Element { | |||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||
}, [posts]); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
const filterAdContent = ( | ||||||||||||||||||||||||||||||
data: { | ||||||||||||||||||||||||||||||
advertisementsConnection?: { | ||||||||||||||||||||||||||||||
edges: { | ||||||||||||||||||||||||||||||
node: InterfaceAdContent; | ||||||||||||||||||||||||||||||
}[]; | ||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||
currentOrgId: string, | ||||||||||||||||||||||||||||||
currentDate: Date = new Date(), | ||||||||||||||||||||||||||||||
): InterfaceAdContent[] => { | ||||||||||||||||||||||||||||||
const { advertisementsConnection } = data; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
if (advertisementsConnection && advertisementsConnection.edges) { | ||||||||||||||||||||||||||||||
const { edges } = advertisementsConnection; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
return edges | ||||||||||||||||||||||||||||||
.map((edge) => edge.node) | ||||||||||||||||||||||||||||||
.filter( | ||||||||||||||||||||||||||||||
(ad: InterfaceAdContent) => | ||||||||||||||||||||||||||||||
ad.organization._id === currentOrgId && | ||||||||||||||||||||||||||||||
new Date(ad.endDate) > currentDate, | ||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
return []; | ||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
const getCardProps = (node: InterfacePostNode): InterfacePostCard => { | ||||||||||||||||||||||||||||||
const { | ||||||||||||||||||||||||||||||
creator, | ||||||||||||||||||||||||||||||
|
@@ -321,21 +332,18 @@ export default function home(): JSX.Element { | |||||||||||||||||||||||||||||
> | ||||||||||||||||||||||||||||||
<h2>{t('feed')}</h2> | ||||||||||||||||||||||||||||||
{pinnedPosts.length > 0 && ( | ||||||||||||||||||||||||||||||
<div> | ||||||||||||||||||||||||||||||
<p className="fs-5 mt-5">{t(`pinnedPosts`)}</p> | ||||||||||||||||||||||||||||||
<div className={` ${styles.pinnedPostsCardsContainer}`}> | ||||||||||||||||||||||||||||||
{pinnedPosts.map(({ node }: { node: InterfacePostNode }) => { | ||||||||||||||||||||||||||||||
const cardProps = getCardProps(node); | ||||||||||||||||||||||||||||||
return <PostCard key={node._id} {...cardProps} />; | ||||||||||||||||||||||||||||||
})} | ||||||||||||||||||||||||||||||
</div> | ||||||||||||||||||||||||||||||
</div> | ||||||||||||||||||||||||||||||
<Carousel responsive={responsive}> | ||||||||||||||||||||||||||||||
{pinnedPosts.map(({ node }: { node: InterfacePostNode }) => { | ||||||||||||||||||||||||||||||
const cardProps = getCardProps(node); | ||||||||||||||||||||||||||||||
return <PostCard key={node._id} {...cardProps} />; | ||||||||||||||||||||||||||||||
})} | ||||||||||||||||||||||||||||||
</Carousel> | ||||||||||||||||||||||||||||||
)} | ||||||||||||||||||||||||||||||
</div> | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
{filteredAd.length > 0 && ( | ||||||||||||||||||||||||||||||
{adContent.length > 0 && ( | ||||||||||||||||||||||||||||||
<div data-testid="promotedPostsContainer"> | ||||||||||||||||||||||||||||||
{filteredAd.map((post: InterfaceAdContent) => ( | ||||||||||||||||||||||||||||||
{adContent.map((post: Ad) => ( | ||||||||||||||||||||||||||||||
<PromotedPost | ||||||||||||||||||||||||||||||
key={post._id} | ||||||||||||||||||||||||||||||
id={post._id} | ||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tip
Codebase Verification
The inspection of the relevant lines indicates that:
src/components/OrgPostCard/OrgPostCard.tsx
, thetitle
parameter is included in thetoggle
mutation call.src/components/OrgPostCard/OrgPostCard.test.tsx
, thetitle
parameter is not included in the test's mutation call.To avoid runtime errors, the test file should also include the
title
parameter. Here are the specific locations that need attention:src/components/OrgPostCard/OrgPostCard.test.tsx
: Ensure thetitle
parameter is included in the mutation call.Analysis chain
The addition of the
title
parameter to theTOGGLE_PINNED_POST
mutation enhances the functionality by allowing the title of the post to be included when toggling its pinned status. Ensure that all calls to this mutation in the frontend now include this new parameter to avoid runtime errors.The search results provided context around the instances of
TOGGLE_PINNED_POST
, but they still do not clearly show whether thetitle
parameter is being included in the mutation calls. To definitively verify this, we need to inspect the relevant lines more closely.The next step is to extract the specific lines of code where the mutation is called and check if the
title
parameter is included.Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 70
Script:
Length of output: 497
Script:
Length of output: 548
Script:
Length of output: 4239
Script:
Length of output: 738