Skip to content

Commit

Permalink
removed hostile mission warn after 3 hours of arrival
Browse files Browse the repository at this point in the history
  • Loading branch information
ametel01 committed Jan 21, 2024
1 parent 22e42d1 commit 53b4d77
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions packages/frontend/src/components/ui/HostileMissions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ const RightAlignedCell = styled(Cell)({
textAlign: 'right',
});

const shouldDisplayMission = (mission: HostileMission) => {
const arrivalTimeInSeconds = Number(mission.time_arrival);
const currentTimeInSeconds = Date.now() / 1000;
const timeDifferenceInSeconds = arrivalTimeInSeconds - currentTimeInSeconds;

// Check if the time difference is within 3 hours
return timeDifferenceInSeconds > -3 * 3600;
};

const getTimeDifference = (arrivalTime: number) => {
const currentTime = Date.now() / 1000; // Convert current time to seconds
const differenceInSeconds = arrivalTime - currentTime;
Expand Down Expand Up @@ -132,24 +141,24 @@ interface HostileMissionsProps {
export const HostileMissions = ({ planetId }: HostileMissionsProps) => {
const hostileMissions = useGetHostileMissions(Number(planetId));

const displayedMissions = hostileMissions?.filter(shouldDisplayMission) || [];

return (
<>
{hostileMissions === undefined ? (
{displayedMissions.length === 0 ? (
<CircularProgress />
) : hostileMissions.length === 0 ? null : (
) : (
<Container>
<TitleContainer>
{hostileMissions && hostileMissions.length > 0 && (
<StyledWarningIcon />
)}
{displayedMissions.length > 0 && <StyledWarningIcon />}
<Title variant="h6">Hostile Missions</Title>
</TitleContainer>
<HeaderRow>
<Cell>Origin</Cell>
<Cell>Arrival</Cell>
<RightAlignedCell>Ships</RightAlignedCell>
</HeaderRow>
{hostileMissions.map((mission) => (
{displayedMissions.map((mission) => (
<MissionRow mission={mission} key={mission.id_at_origin} />
))}
</Container>
Expand Down

0 comments on commit 53b4d77

Please sign in to comment.