Skip to content
Closed
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
28 changes: 26 additions & 2 deletions src/hooks/ChainSyncManger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
// init store's chain from location (once at mount time)
useEffect(() => {
setChainId(INITIAL_CHAIN.id);
}, []);

Check warning on line 36 in src/hooks/ChainSyncManger.ts

View workflow job for this annotation

GitHub Actions / build

React Hook useEffect has a missing dependency: 'setChainId'. Either include it or remove the dependency array

// update store with user account's state
useEffect(() => {
Expand Down Expand Up @@ -91,8 +91,32 @@
const slug = getChainFromId(chainId)?.slug;

if (slug !== chainSlug && !isNavigating.current) {
const [, ...rest] = pathname.split('/').filter(Boolean);
const newPath = `/${slug}/${rest.join('/')}`;
const pathSegments = pathname.split('/').filter(Boolean);

const detailToListRouteMap: Record<string, string> = {
task: 'tasks',
deal: 'deals',
dataset: 'datasets',
app: 'apps',
workerpool: 'workerpools',
address: '',
tx: '',
search: '',
};

const detailRoute = pathSegments[1];
const isOnDetailPage =
pathSegments.length >= 3 && detailRoute in detailToListRouteMap;

let newPath: string;
if (isOnDetailPage) {
const listRoute = detailToListRouteMap[detailRoute];
newPath = listRoute ? `/${slug}/${listRoute}` : `/${slug}`;
} else {
const [, ...rest] = pathSegments;
newPath = `/${slug}/${rest.join('/')}`;
}

isNavigating.current = true;
const navigationResult = navigate({ to: newPath, replace: true });
if (navigationResult instanceof Promise) {
Expand Down
Loading