Skip to content

Commit

Permalink
Sort feeds from high to low (on the map) (#717)
Browse files Browse the repository at this point in the history
  • Loading branch information
skanderm authored Nov 25, 2024
1 parent 37dd949 commit 8286f81
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions ui/src/pages/listen/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import { Container, Stack, Typography } from "@mui/material";
import { dehydrate, QueryClient } from "@tanstack/react-query";
import Head from "next/head";
import { useMemo } from "react";

import FeedCard from "@/components/FeedCard";
import { getMapLayout } from "@/components/layouts/MapLayout";
import { useFeedsQuery } from "@/graphql/generated";
import type { NextPageWithLayout } from "@/pages/_app";

const FeedsPage: NextPageWithLayout = () => {
const feeds = useFeedsQuery().data?.feeds;
const feedsQueryResult = useFeedsQuery();

if (!feeds) return null;
// Sort feeds by high latitude to low (to match the order on the map)
const sortedFeeds = useMemo(
() =>
feedsQueryResult.data?.feeds.sort((a, b) => b.latLng.lat - a.latLng.lat),
[feedsQueryResult.data],
);

if (!sortedFeeds) return null;

return (
<div>
Expand All @@ -27,7 +35,7 @@ const FeedsPage: NextPageWithLayout = () => {
Select a location to start listening live
</Typography>
<Stack spacing={4} mt={4}>
{feeds.map((feed) => (
{sortedFeeds.map((feed) => (
<FeedCard key={feed.id} feed={feed} />
))}
</Stack>
Expand Down

0 comments on commit 8286f81

Please sign in to comment.