Skip to content

Commit

Permalink
Select first online feed on layout load (#675)
Browse files Browse the repository at this point in the history
* Select first online feed on load

* Inline first feed result
  • Loading branch information
skanderm authored Nov 1, 2024
1 parent e87b753 commit 8ef4852
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ui/src/components/layouts/MapLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function MapLayout({ children }: { children: ReactNode }) {
const [currentFeed, setCurrentFeed] = useState(feed);
const [map, setMap] = useState<LeafletMap>();
const feeds = useFeedsQuery().data?.feeds ?? [];
const firstOnlineFeed = feeds.filter(({ online }) => online)[0];

// update the currentFeed only if there's a new feed
useEffect(() => {
Expand All @@ -52,7 +53,10 @@ function MapLayout({ children }: { children: ReactNode }) {
map?.setZoom(9);
map?.panTo(feed.latLng);
}
}, [feed, map, currentFeed]);
if (!feed && !currentFeed && firstOnlineFeed) {
setCurrentFeed(firstOnlineFeed);
}
}, [feed, map, currentFeed, firstOnlineFeed]);

const invalidateSize = () => {
if (map) {
Expand Down
4 changes: 4 additions & 0 deletions ui/src/graphql/generated/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2338,6 +2338,8 @@ export type FeedsQuery = {
imageUrl?: string | null;
thumbUrl?: string | null;
mapUrl?: string | null;
bucket: string;
online?: boolean | null;
latLng: { __typename?: "LatLng"; lat: number; lng: number };
}>;
};
Expand Down Expand Up @@ -3207,6 +3209,8 @@ export const FeedsDocument = `
imageUrl
thumbUrl
mapUrl
bucket
online
}
}
`;
Expand Down
2 changes: 2 additions & 0 deletions ui/src/graphql/queries/listFeeds.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ query feeds {
imageUrl
thumbUrl
mapUrl
bucket
online
}
}

0 comments on commit 8ef4852

Please sign in to comment.