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

Add Tab for Map and Table #28

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,4 @@
"vite-tsconfig-paths": "^4.2.2",
"vitest": "^1.1.0"
}
}
}
19 changes: 15 additions & 4 deletions src/App/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,26 @@ import {
import mapboxgl from 'mapbox-gl';

import { mbtoken } from '#config';
import RouteContext from '#contexts/route';

import { unwrappedRoutes } from './routes';
import {
unwrappedRoutes,
wrappedRoutes,
} from './routes';

const router = createBrowserRouter(unwrappedRoutes);
mapboxgl.accessToken = mbtoken;

mapboxgl.accessToken = mbtoken || '';
mapboxgl.setRTLTextPlugin(
'https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-rtl-text/v0.2.3/mapbox-gl-rtl-text.js',
// eslint-disable-next-line no-console
(err) => { console.error(err); },
true,
);
function App() {
return (
<RouterProvider router={router} />
<RouteContext.Provider value={wrappedRoutes}>
<RouterProvider router={router} />
</RouteContext.Provider>
);
}

Expand Down
18 changes: 18 additions & 0 deletions src/App/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,28 @@ const preferences = myWrapRoute({
parent: root,
});

const map = myWrapRoute({
title: '',
path: 'map',
component: () => import('#views/Home'),
componentProps: {},
parent: root,
});

const table = myWrapRoute({
title: '',
path: 'table',
component: () => import('#views/Home'),
componentProps: {},
parent: root,
});

export const wrappedRoutes = {
root,
home,
preferences,
map,
table,
};

export const unwrappedRoutes = unwrapRoute(Object.values(wrappedRoutes));
Expand Down
10 changes: 10 additions & 0 deletions src/contexts/domain.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { createContext } from 'react';

const DomainContext = createContext({
// eslint-disable-next-line no-console
register: () => { console.warn('DomainContext::register called before it was initialized'); },
// eslint-disable-next-line no-console
invalidate: () => { console.warn('DomainContext::invalidate called before it was initialized'); },
});

export default DomainContext;
10 changes: 10 additions & 0 deletions src/contexts/route.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { createContext } from 'react';

import type { WrappedRoutes } from '../App/routes';

const RouteContext = createContext<WrappedRoutes>(
// NOTE: we will make sure the route information is passed
{} as WrappedRoutes,
);

export default RouteContext;
38 changes: 38 additions & 0 deletions src/contexts/user.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { createContext } from 'react';

export interface UserAuth {
id: number;
// FIXME: why do we not use displayName for other users?
displayName: string;
token: string;
expires: string;

username: string;
firstName: string | undefined;
lastName: string | undefined;
}

export interface UserContextProps {
userAuth: UserAuth | undefined,
setUserAuth: (userDetails: UserAuth) => void,
hydrateUserAuth: () => void;
removeUserAuth: () => void;
}

const UserContext = createContext<UserContextProps>({
setUserAuth: () => {
// eslint-disable-next-line no-console
console.warn('UserContext::setUser called without provider');
},
hydrateUserAuth: () => {
// eslint-disable-next-line no-console
console.warn('UserContext::hydrateUser called without provider');
},
removeUserAuth: () => {
// eslint-disable-next-line no-console
console.warn('UserContext::removeUser called without provider');
},
userAuth: undefined,
});

export default UserContext;
6 changes: 4 additions & 2 deletions src/views/AlertMap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
DURATION_MAP_ZOOM,
} from '#utils/constants';
import { adminFillLayerOptions } from '#utils/map';
import AlertTab from '#views/AlertTab';

Check failure on line 18 in src/views/AlertMap/index.tsx

View workflow job for this annotation

GitHub Actions / Lint JS

Using exported name 'AlertTab' as identifier for default export

import i18n from './i18n.json';
import styles from './styles.module.css';
Expand All @@ -24,7 +25,7 @@
bbox: LngLatBoundsLike | undefined;
}

function OngoingAlertMap(props: Props) {
export function Component(props: Props) {
const {
className,
bbox,
Expand All @@ -47,6 +48,7 @@
</Link>
)}
>
<AlertTab />
<BaseMap
baseLayers={(
<MapLayer
Expand All @@ -69,4 +71,4 @@
);
}

export default OngoingAlertMap;
export default Component;
8 changes: 8 additions & 0 deletions src/views/AlertTab/i18n.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"namespace": "AlertTab",
"strings": {
"ongoingAlertMapTabTitle": "Map",
"ongoingAlertTableTabTitle": "Table"
}

}
43 changes: 43 additions & 0 deletions src/views/AlertTab/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import {
useCallback,
useState,
} from 'react';
import {
Tab,
TabList,
} from '@ifrc-go/ui';
import { useTranslation } from '@ifrc-go/ui/hooks';

import i18n from './i18n.json';
import styles from './styles.module.css';

type TabKeys = 'map' | 'table';

export function AlertTab() {
const strings = useTranslation(i18n);
const [activeTab, setActiveTab] = useState<TabKeys>('map');

const handleTabChange = useCallback((newTab: TabKeys) => {
setActiveTab(newTab);
}, []);

return (
<TabList className={styles.tabList}>
<Tab
value={activeTab}
name="map"
onChange={() => handleTabChange('map')}
>
{strings.ongoingAlertMapTabTitle}
</Tab>
<Tab
value={activeTab}
name="table"
onChange={() => handleTabChange('table')}
>
{strings.ongoingAlertTableTabTitle}
</Tab>
</TabList>
);
}
export default AlertTab;
4 changes: 4 additions & 0 deletions src/views/AlertTab/styles.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.tabList {
display: flex;
justify-content: flex-start;
}
Loading