Skip to content

Commit

Permalink
only show big share back button when all schedules haven't been shared
Browse files Browse the repository at this point in the history
  • Loading branch information
yatharth-b committed Apr 1, 2024
1 parent 1cfafc4 commit edf1d2a
Showing 1 changed file with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import React, { useContext, useMemo } from 'react';
import useLocalStorageState from 'use-local-storage-state';

import { ScheduleContext } from '../../contexts';

type ComparisonContainerShareBack = {
friendId: string;
friendName: string;
Expand All @@ -16,6 +18,8 @@ export default function ComparisonContainerShareBack({
setModalEmail,
setModalOpen,
}: ComparisonContainerShareBack): React.ReactElement | null {
const [{ allFriends, allVersionNames }] = useContext(ScheduleContext);

const [hasSeen, setHasSeen] = useLocalStorageState(
`share-back-invitation-${friendId}`,
{
Expand All @@ -24,7 +28,28 @@ export default function ComparisonContainerShareBack({
}
);

if (hasSeen) {
const schedulesShared = useMemo(() => {
return Object.keys(allFriends)
.map((version_id) => {
if (
friendId &&
allFriends[version_id] &&
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
friendId in allFriends[version_id]!
) {
const versionName = allVersionNames.filter(
(v) => v.id === version_id
);
if (versionName.length > 0) {
return versionName[0]?.name;
}
}
return undefined;
})
.filter((v) => v) as string[];
}, [friendId, allFriends, allVersionNames]);

if (hasSeen || schedulesShared.length === allVersionNames.length) {
return null;
}

Expand Down

0 comments on commit edf1d2a

Please sign in to comment.