Skip to content

Commit b4bb44e

Browse files
committed
Format
1 parent 9d638ee commit b4bb44e

File tree

17 files changed

+96
-102
lines changed

17 files changed

+96
-102
lines changed

site/src/app.tsx

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -39,71 +39,71 @@ export const App: React.FC = () => {
3939
}}
4040
>
4141
<XServiceProvider>
42-
<ThemeProvider theme={light}>
43-
<CssBaseline />
42+
<ThemeProvider theme={light}>
43+
<CssBaseline />
4444

45-
<Routes>
46-
<Route path="/">
47-
<Route
48-
index
49-
element={
50-
<RequireAuth>
51-
<IndexPage />
52-
</RequireAuth>
53-
}
54-
/>
55-
56-
<Route path="login" element={<SignInPage />} />
57-
<Route path="healthz" element={<HealthzPage />} />
58-
<Route path="cli-auth" element={<CliAuthenticationPage />} />
59-
60-
<Route path="projects">
45+
<Routes>
46+
<Route path="/">
6147
<Route
6248
index
6349
element={
64-
<AuthAndNav>
65-
<ProjectsPage />
66-
</AuthAndNav>
50+
<RequireAuth>
51+
<IndexPage />
52+
</RequireAuth>
6753
}
6854
/>
69-
<Route path=":organization/:project">
55+
56+
<Route path="login" element={<SignInPage />} />
57+
<Route path="healthz" element={<HealthzPage />} />
58+
<Route path="cli-auth" element={<CliAuthenticationPage />} />
59+
60+
<Route path="projects">
7061
<Route
7162
index
7263
element={
7364
<AuthAndNav>
74-
<ProjectPage />
65+
<ProjectsPage />
7566
</AuthAndNav>
7667
}
7768
/>
69+
<Route path=":organization/:project">
70+
<Route
71+
index
72+
element={
73+
<AuthAndNav>
74+
<ProjectPage />
75+
</AuthAndNav>
76+
}
77+
/>
78+
<Route
79+
path="create"
80+
element={
81+
<RequireAuth>
82+
<CreateWorkspacePage />
83+
</RequireAuth>
84+
}
85+
/>
86+
</Route>
87+
</Route>
88+
89+
<Route path="workspaces">
7890
<Route
79-
path="create"
91+
path=":workspace"
8092
element={
81-
<RequireAuth>
82-
<CreateWorkspacePage />
83-
</RequireAuth>
93+
<AuthAndNav>
94+
<WorkspacePage />
95+
</AuthAndNav>
8496
}
8597
/>
8698
</Route>
87-
</Route>
8899

89-
<Route path="workspaces">
90-
<Route
91-
path=":workspace"
92-
element={
93-
<AuthAndNav>
94-
<WorkspacePage />
95-
</AuthAndNav>
96-
}
97-
/>
98-
</Route>
99-
100-
{/* Using path="*"" means "match anything", so this route
100+
{/* Using path="*"" means "match anything", so this route
101101
acts like a catch-all for URLs that we don't have explicit
102102
routes for. */}
103-
<Route path="*" element={<NotFoundPage />} />
104-
</Route>
105-
</Routes>
106-
</ThemeProvider>
103+
<Route path="*" element={<NotFoundPage />} />
104+
</Route>
105+
</Routes>
106+
</ThemeProvider>
107107
</XServiceProvider>
108108
</SWRConfig>
109109
</Router>

site/src/components/Navbar/NavbarView.stories.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import { Story } from "@storybook/react"
32
import React from "react"
43
import { NavbarView, NavbarViewProps } from "./NavbarView"
@@ -15,8 +14,8 @@ const Template: Story<NavbarViewProps> = (args: NavbarViewProps) => <NavbarView
1514

1615
export const Primary = Template.bind({})
1716
Primary.args = {
18-
user: { id: '1', username: 'CathyCoder', email: 'cathy@coder.com', created_at: 'dawn'},
17+
user: { id: "1", username: "CathyCoder", email: "cathy@coder.com", created_at: "dawn" },
1918
onSignOut: () => {
2019
return Promise.resolve()
2120
},
22-
}
21+
}

site/src/components/Navbar/NavbarView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react'
1+
import React from "react"
22
import Button from "@material-ui/core/Button"
33
import { makeStyles } from "@material-ui/core/styles"
44
import { Link } from "react-router-dom"

site/src/components/Navbar/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { XServiceContext } from "../../xServices/StateContext"
55

66
export const Navbar: React.FC = () => {
77
const xServices = useContext(XServiceContext)
8-
const [userState, userSend] = useActor(xServices.userXService);
8+
const [userState, userSend] = useActor(xServices.userXService)
99
const { me } = userState.context
1010
const onSignOut = () => userSend("SIGN_OUT")
1111

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import React from "react";
2-
import { Navbar } from "../Navbar";
3-
import { RequireAuth, RequireAuthProps } from "./RequireAuth";
1+
import React from "react"
2+
import { Navbar } from "../Navbar"
3+
import { RequireAuth, RequireAuthProps } from "./RequireAuth"
44

55
export const AuthAndNav: React.FC<RequireAuthProps> = ({ children }) => (
66
<RequireAuth>
@@ -9,4 +9,4 @@ export const AuthAndNav: React.FC<RequireAuthProps> = ({ children }) => (
99
{children}
1010
</>
1111
</RequireAuth>
12-
)
12+
)

site/src/components/Page/RequireAuth.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export interface RequireAuthProps {
1010

1111
export const RequireAuth: React.FC<RequireAuthProps> = ({ children }) => {
1212
const xServices = useContext(XServiceContext)
13-
const [userState] = useActor(xServices.userXService);
13+
const [userState] = useActor(xServices.userXService)
1414
const location = useLocation()
1515

1616
if (userState.matches("signedOut") || !userState.context.me) {
@@ -21,4 +21,3 @@ export const RequireAuth: React.FC<RequireAuthProps> = ({ children }) => {
2121
return children
2222
}
2323
}
24-

site/src/components/SignIn/SignInForm.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,11 @@ export const SignInForm: React.FC<SignInFormProps> = ({ isLoading, authErrorMess
8787
placeholder="Password"
8888
variant="outlined"
8989
/>
90-
{authErrorMessage && <FormHelperText data-testid={"sign-in-error"} error>{authErrorMessage}</FormHelperText>}
90+
{authErrorMessage && (
91+
<FormHelperText data-testid={"sign-in-error"} error>
92+
{authErrorMessage}
93+
</FormHelperText>
94+
)}
9195
</div>
9296
<div className={styles.submitBtn}>
9397
<LoadingButton
@@ -98,7 +102,7 @@ export const SignInForm: React.FC<SignInFormProps> = ({ isLoading, authErrorMess
98102
type="submit"
99103
variant="contained"
100104
>
101-
{ isLoading ? '' : "Sign In" }
105+
{isLoading ? "" : "Sign In"}
102106
</LoadingButton>
103107
</div>
104108
</form>

site/src/pages/cli-auth.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { XServiceContext } from "../xServices/StateContext"
99

1010
export const CliAuthenticationPage: React.FC = () => {
1111
const xServices = useContext(XServiceContext)
12-
const [userState] = useActor(xServices.userXService);
12+
const [userState] = useActor(xServices.userXService)
1313
const { me } = userState.context
1414

1515
const styles = useStyles()

site/src/pages/login.test.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ describe("SignInPage", () => {
1010
history.replace("/login")
1111
// appear logged out
1212
server.use(
13-
rest.get('/api/v2/users/me', (req, res, ctx) => {
14-
return res(
15-
ctx.status(401),
16-
ctx.json({message: 'no user here'}))
17-
})
13+
rest.get("/api/v2/users/me", (req, res, ctx) => {
14+
return res(ctx.status(401), ctx.json({ message: "no user here" }))
15+
}),
1816
)
1917
})
2018

@@ -31,10 +29,8 @@ describe("SignInPage", () => {
3129
const { container } = render(<SignInPage />)
3230
// Make login fail
3331
server.use(
34-
rest.post('/api/v2/users/login', async (req, res, ctx) => {
35-
return res(
36-
ctx.status(500),
37-
ctx.json({message: 'nope'}))
32+
rest.post("/api/v2/users/login", async (req, res, ctx) => {
33+
return res(ctx.status(500), ctx.json({ message: "nope" }))
3834
}),
3935
)
4036

site/src/pages/login.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const SignInPage: React.FC = () => {
3232
const styles = useStyles()
3333
const location = useLocation()
3434
const xServices = useContext(XServiceContext)
35-
const [userState, userSend] = useActor(xServices.userXService);
35+
const [userState, userSend] = useActor(xServices.userXService)
3636
const isLoading = userState.hasTag("loading")
3737
const redirectTo = getRedirectFromLocation(location)
3838
const authErrorMessage = userState.context.authError ? (userState.context.authError as Error).message : undefined

site/src/setupTests.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
import { server } from './test_helpers/server'
1+
import { server } from "./test_helpers/server"
22

33
// Establish API mocking before all tests.
4-
beforeAll(() => server.listen({
5-
onUnhandledRequest: "warn"
6-
}))
4+
beforeAll(() =>
5+
server.listen({
6+
onUnhandledRequest: "warn",
7+
}),
8+
)
79

810
// Reset any request handlers that we may add during the tests,
911
// so they don't affect other tests.
1012
afterEach(() => server.resetHandlers())
1113

1214
// Clean up after the tests are finished.
13-
afterAll(() => server.close())
15+
afterAll(() => server.close())

site/src/test_helpers/entities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Provisioner, Organization, Project, Workspace, UserResponse } from "../
22

33
export const MockSessionToken = { session_token: "my-session-token" }
44

5-
export const MockAPIKey = { key: "my-api-key" }
5+
export const MockAPIKey = { key: "my-api-key" }
66

77
export const MockUser: UserResponse = {
88
id: "test-user-id",

site/src/test_helpers/handlers.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { rest } from 'msw'
2-
import * as M from './entities'
1+
import { rest } from "msw"
2+
import * as M from "./entities"
33

44
export const handlers = [
55
rest.post("/api/v2/users/me/workspaces", async (req, res, ctx) => {
@@ -16,5 +16,5 @@ export const handlers = [
1616
}),
1717
rest.get("/api/v2/users/me/keys", async (req, res, ctx) => {
1818
return res(ctx.status(200), ctx.json(M.MockAPIKey))
19-
})
20-
]
19+
}),
20+
]

site/src/test_helpers/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const WrapperComponent: React.FC = ({ children }) => {
1313
return (
1414
<HistoryRouter history={history}>
1515
<XServiceProvider>
16-
<ThemeProvider theme={dark}>{children}</ThemeProvider>
16+
<ThemeProvider theme={dark}>{children}</ThemeProvider>
1717
</XServiceProvider>
1818
</HistoryRouter>
1919
)

site/src/test_helpers/server.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { setupServer } from 'msw/node'
2-
import { handlers } from './handlers'
1+
import { setupServer } from "msw/node"
2+
import { handlers } from "./handlers"
33

44
// This configures a request mocking server with the given request handlers.
5-
export const server = setupServer(...handlers)
5+
export const server = setupServer(...handlers)

site/src/xServices/StateContext.tsx

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,24 @@
1-
import React, { createContext } from 'react';
2-
import { useInterpret } from '@xstate/react';
3-
import { ActorRefFrom } from 'xstate';
4-
import { userMachine } from './user/userXService';
1+
import React, { createContext } from "react"
2+
import { useInterpret } from "@xstate/react"
3+
import { ActorRefFrom } from "xstate"
4+
import { userMachine } from "./user/userXService"
55

66
interface XServiceContextType {
7-
userXService: ActorRefFrom<typeof userMachine>;
7+
userXService: ActorRefFrom<typeof userMachine>
88
}
99

1010
/**
1111
* Consuming this Context will not automatically cause rerenders because
1212
* the xServices in it are static references.
13-
*
14-
* To use one of the xServices, `useActor` will access all its state
15-
* (causing re-renders for any changes to that one xService) and
13+
*
14+
* To use one of the xServices, `useActor` will access all its state
15+
* (causing re-renders for any changes to that one xService) and
1616
* `useSelector` will access just one piece of state.
1717
*/
18-
export const XServiceContext = createContext(
19-
{} as XServiceContextType,
20-
);
18+
export const XServiceContext = createContext({} as XServiceContextType)
2119

2220
export const XServiceProvider: React.FC = ({ children }) => {
23-
const userXService = useInterpret(userMachine, { devTools: true });
21+
const userXService = useInterpret(userMachine, { devTools: true })
2422

25-
return (
26-
<XServiceContext.Provider value={{ userXService }}>
27-
{children}
28-
</XServiceContext.Provider>
29-
);
30-
};
23+
return <XServiceContext.Provider value={{ userXService }}>{children}</XServiceContext.Provider>
24+
}

site/src/xServices/user/userXService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createMachine, assign } from "xstate"
2-
import * as Types from '../../api/types'
3-
import * as API from '../../api'
2+
import * as Types from "../../api/types"
3+
import * as API from "../../api"
44

55
export interface UserContext {
66
getUserError?: Error | unknown // unknown is a concession while I work out typing issues

0 commit comments

Comments
 (0)