Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select first online feed on layout load #675

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be fine for SSR since the query gets refetched by default (refetchOnMount is default true): https://tanstack.com/query/latest/docs/framework/react/reference/useQuery#usequery


// 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
}
}
Loading