Skip to content

Commit 134036d

Browse files
author
Andrea Ceriani
committed
Add System Provider
1 parent a1ec5af commit 134036d

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

app/routes/_app._index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import type { System } from '~/types/api-status'
1717
import { logInfoHttp } from '~/helpers/log-helper'
1818
// utils
1919
import { authenticator, getAuthAccessToken } from '~/utils/auth.server'
20+
// contexts
21+
import { useSystem } from '~/contexts/SystemContext'
2022
// apis
2123
import { getSystems } from '~/apis/status-api'
2224
import { getJobs } from '~/apis/compute-api'
@@ -69,7 +71,8 @@ export const loader: LoaderFunction = async ({ request }: LoaderFunctionArgs) =>
6971
}
7072

7173
export default function AppIndexRoute() {
72-
const { systems, dashboardJobs }: any = useLoaderData()
74+
const { systems } = useSystem()
75+
const { dashboardJobs }: any = useLoaderData()
7376
return <DashboardView systems={systems} dashboardJobs={dashboardJobs} />
7477
}
7578

app/routes/_app.tsx

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ import type { LinksFunction, LoaderFunction, LoaderFunctionArgs } from '@remix-r
1212
import stylesheet from '~/styles/app.css?url'
1313
// configs
1414
import base from '~/configs/base.config'
15+
// apis
16+
import { getSystems } from '~/apis/status-api'
1517
// layouts
1618
import AppLayout from '~/layouts/AppLayout'
1719
// helpers
1820
import { getNotificationMessage } from '~/helpers/notification-helper'
1921
// utils
20-
import { authenticator } from '~/utils/auth.server'
22+
import { authenticator, getAuthAccessToken } from '~/utils/auth.server'
23+
import { SystemProvider } from '~/contexts/SystemContext'
2124

2225
export const links: LinksFunction = () => [{ rel: 'stylesheet', href: stylesheet }]
2326

@@ -26,10 +29,14 @@ export const loader: LoaderFunction = async ({ request }: LoaderFunctionArgs) =>
2629
const auth = await authenticator.isAuthenticated(request, {
2730
failureRedirect: '/login',
2831
})
32+
// Get auth access token
33+
const accessToken = await getAuthAccessToken(request)
2934
// Create a headers object
3035
const headers = new Headers()
3136
// Get notification messages
3237
const notificationMessages = await getNotificationMessage(request, headers)
38+
// Call api/s and fetch data
39+
const { systems } = await getSystems(accessToken)
3340
// Return json
3441
return json(
3542
{
@@ -43,6 +50,7 @@ export const loader: LoaderFunction = async ({ request }: LoaderFunctionArgs) =>
4350
logoPath: base.logoPath,
4451
authUser: auth.user,
4552
notificationMessages: notificationMessages,
53+
systems: systems,
4654
},
4755
{
4856
headers: headers,
@@ -63,19 +71,22 @@ export default function AppLayoutRoute() {
6371
environment,
6472
authUser,
6573
notificationMessages,
74+
systems,
6675
}: any = data
6776
return (
68-
<AppLayout
69-
appName={appName}
70-
environment={environment}
71-
appVersion={appVersion}
72-
companyName={companyName}
73-
logoPath={logoPath}
74-
supportUrl={supportUrl}
75-
repoUrl={repoUrl}
76-
docUrl={docUrl}
77-
authUser={authUser}
78-
notificationMessages={notificationMessages}
79-
/>
77+
<SystemProvider systems={systems}>
78+
<AppLayout
79+
appName={appName}
80+
environment={environment}
81+
appVersion={appVersion}
82+
companyName={companyName}
83+
logoPath={logoPath}
84+
supportUrl={supportUrl}
85+
repoUrl={repoUrl}
86+
docUrl={docUrl}
87+
authUser={authUser}
88+
notificationMessages={notificationMessages}
89+
/>
90+
</SystemProvider>
8091
)
8192
}

0 commit comments

Comments
 (0)