Skip to content

Commit

Permalink
fix: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Kodylow committed Sep 23, 2024
1 parent 7b0aacf commit a1b2f56
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
8 changes: 2 additions & 6 deletions apps/router/src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@ export const Header = React.memo(function Header() {
const { guardians, gateways } = useAppContext();
const { type, id } = useActiveService();
const activeService = useMemo(() => {
if (type === 'guardian') {
return guardians[id];
} else if (type === 'gateway') {
return gateways[id];
}
return null;
const serviceMap = { guardian: guardians, gateway: gateways };
return serviceMap[type]?.[id] ?? null;
}, [type, id, guardians, gateways]);

const hasServices =
Expand Down
9 changes: 7 additions & 2 deletions apps/router/src/hooks/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { useLocation } from 'react-router-dom';

export const useActiveService = () => {
export const useActiveService = (): {
type: 'guardian' | 'gateway';
id: string;
} => {
const location = useLocation();
const [type, id] = location.pathname.split('/').filter(Boolean);

if (type !== 'guardian' && type !== 'gateway') {
throw new Error('Invalid service type');
}
return {
type,
id,
Expand Down

0 comments on commit a1b2f56

Please sign in to comment.