Skip to content

Commit

Permalink
#35: Fixes sort operators functions
Browse files Browse the repository at this point in the history
  • Loading branch information
williamquintas authored and arthursimas1 committed Jun 1, 2023
1 parent d1ab1a5 commit 1918f6f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 8 additions & 2 deletions components/MapContainer/MapContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@ const MapContainer: FunctionComponent = () => {
const sortOperator = (
{ date: date1, time: time1 }: ICoordinatesData,
{ date: date2, time: time2 }: ICoordinatesData
): number => `${date1}T${time1}` - `${date2}T${time2}`;
): number => {
const datetime1 = `${date1}T${time1}`;
const datetime2 = `${date2}T${time2}`;
return datetime2.localeCompare(datetime1);
};

const session = useAppSelector(selectSession);
const { date, time } =
session?.entities
?.map(({ coordinates }) => coordinates?.at(-1))
?.map(
({ coordinates }) => coordinates?.at(-1) ?? ({} as ICoordinatesData)
)
?.sort(sortOperator)
?.at(-1) ?? {};

Expand Down
6 changes: 4 additions & 2 deletions pages/api/session/[sessionId]/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,17 @@ const storeCoordinatesData = async (
{ date: date1, time: time1 }: ICoordinatesData,
{ date: date2, time: time2 }: ICoordinatesData
): number => {
return `${date1}T${time1}` - `${date2}T${time2}`;
const datetime1 = `${date1}T${time1}`;
const datetime2 = `${date2}T${time2}`;
return datetime2.localeCompare(datetime1);
};

const lastRecordData =
(await coordinatesCollection.get()).docs
.map((doc) => doc.data() as ICoordinatesData)
.filter(({ id }) => id === coordinatesData.id)
.sort(sortOperator)
.at(-1) ?? {};
.at(-1) ?? ({} as ICoordinatesData);

const isNewRecordBeforeLastOne =
lastRecordData?.date >= coordinatesData.date &&
Expand Down

0 comments on commit 1918f6f

Please sign in to comment.