- Notifications
You must be signed in to change notification settings - Fork928
chore: use emotion for styling (pt. 5)#10261
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
8ef2a58
c455b38
4e033c6
8d7e9a8
eeb1b93
04adebe
2b49f62
57b1f68
715282c
8927e23
1857b71
5bacdda
9924a32
d49898c
f4373dd
351e310
196c7a8
3d14e1b
58daeaf
8a5e35f
c8a94a5
7058b7f
0972a1c
2481674
f09e627
7135de3
193c364
007e048
10f041c
ec8cc6e
da1a641
69fd068
fcc868b
4b92f61
c2abccb
9f73611
e3986d2
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
import Button from "@mui/material/Button"; | ||
import Link from "@mui/material/Link"; | ||
import RefreshOutlined from "@mui/icons-material/RefreshOutlined"; | ||
import { type FC, useEffect, useState } from "react"; | ||
import { Helmet } from "react-helmet-async"; | ||
import { css } from "@emotion/css"; | ||
import { useTheme, type Interpolation, type Theme } from "@emotion/react"; | ||
import type { BuildInfoResponse } from "api/typesGenerated"; | ||
import { CopyButton } from "components/CopyButton/CopyButton"; | ||
import { CoderIcon } from "components/Icons/CoderIcon"; | ||
import { FullScreenLoader } from "components/Loader/FullScreenLoader"; | ||
import { Stack } from "components/Stack/Stack"; | ||
import { Margins } from "components/Margins/Margins"; | ||
const fetchDynamicallyImportedModuleError = | ||
@@ -17,7 +18,7 @@ const fetchDynamicallyImportedModuleError = | ||
export type RuntimeErrorStateProps = { error: Error }; | ||
export const RuntimeErrorState: FC<RuntimeErrorStateProps> = ({ error }) => { | ||
consttheme =useTheme(); | ||
const [checkingError, setCheckingError] = useState(true); | ||
const [staticBuildInfo, setStaticBuildInfo] = useState<BuildInfoResponse>(); | ||
const coderVersion = staticBuildInfo?.version; | ||
@@ -52,11 +53,11 @@ export const RuntimeErrorState: FC<RuntimeErrorStateProps> = ({ error }) => { | ||
<title>Something went wrong...</title> | ||
</Helmet> | ||
{!checkingError ? ( | ||
<Marginscss={styles.root}> | ||
<divcss={{ width: "100%" }}> | ||
<CoderIconcss={styles.logo} /> | ||
<h1css={styles.title}>Something went wrong...</h1> | ||
<pcss={styles.text}> | ||
Please try reloading the page, if that doesn‘t work, you can | ||
ask for help in the{" "} | ||
<Link href="https://discord.gg/coder"> | ||
@@ -93,20 +94,33 @@ export const RuntimeErrorState: FC<RuntimeErrorStateProps> = ({ error }) => { | ||
</Button> | ||
</Stack> | ||
{error.stack && ( | ||
<divcss={styles.stack}> | ||
<divcss={styles.stackHeader}> | ||
Stacktrace | ||
<CopyButton | ||
buttonClassName={css` | ||
Member
| ||
background-color: transparent; | ||
border: 0; | ||
border-radius: 999px; | ||
min-height: ${theme.spacing(4)}; | ||
min-width: ${theme.spacing(4)}; | ||
height: ${theme.spacing(4)}; | ||
width: ${theme.spacing(4)}; | ||
& svg { | ||
width: 16px; | ||
height: 16px; | ||
} | ||
`} | ||
text={error.stack} | ||
tooltipTitle="Copy stacktrace" | ||
/> | ||
</div> | ||
<precss={styles.stackCode}>{error.stack}</pre> | ||
</div> | ||
)} | ||
{coderVersion && ( | ||
<divcss={styles.version}>Version: {coderVersion}</div> | ||
)} | ||
</div> | ||
</Margins> | ||
@@ -132,8 +146,8 @@ const getStaticBuildInfo = () => { | ||
} | ||
}; | ||
conststyles = { | ||
root:(theme) => ({ | ||
paddingTop: theme.spacing(4), | ||
paddingBottom: theme.spacing(4), | ||
textAlign: "center", | ||
@@ -142,36 +156,34 @@ const useStyles = makeStyles((theme) => ({ | ||
justifyContent: "center", | ||
minHeight: "100%", | ||
maxWidth: theme.spacing(75), | ||
}), | ||
logo: (theme) => ({ | ||
fontSize: theme.spacing(8), | ||
}), | ||
title:(theme) => ({ | ||
fontSize: theme.spacing(4), | ||
fontWeight: 400, | ||
}), | ||
text:(theme) => ({ | ||
fontSize: 16, | ||
color: theme.palette.text.secondary, | ||
lineHeight: "160%", | ||
marginBottom: theme.spacing(4), | ||
}), | ||
stack:(theme) => ({ | ||
backgroundColor: theme.palette.background.paper, | ||
border: `1px solid ${theme.palette.divider}`, | ||
borderRadius: 4, | ||
marginTop: theme.spacing(8), | ||
display: "block", | ||
textAlign: "left", | ||
}), | ||
stackHeader:(theme) => ({ | ||
fontSize: 10, | ||
textTransform: "uppercase", | ||
fontWeight: 600, | ||
@@ -184,33 +196,18 @@ const useStyles = makeStyles((theme) => ({ | ||
flexAlign: "center", | ||
justifyContent: "space-between", | ||
alignItems: "center", | ||
}), | ||
stackCode:(theme) => ({ | ||
padding: theme.spacing(2), | ||
margin: 0, | ||
wordWrap: "break-word", | ||
whiteSpace: "break-spaces", | ||
}), | ||
version: (theme) => ({ | ||
marginTop: theme.spacing(4), | ||
fontSize: 12, | ||
color: theme.palette.text.secondary, | ||
}), | ||
} satisfies Record<string, Interpolation<Theme>>; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
import { Stack } from "components/Stack/Stack"; | ||
import {typeFC,typeDragEvent, useRef, type ReactNode } from "react"; | ||
import UploadIcon from "@mui/icons-material/CloudUploadOutlined"; | ||
import { useClickable } from "hooks/useClickable"; | ||
import CircularProgress from "@mui/material/CircularProgress"; | ||
import IconButton from "@mui/material/IconButton"; | ||
import RemoveIcon from "@mui/icons-material/DeleteOutline"; | ||
import FileIcon from "@mui/icons-material/FolderOutlined"; | ||
import { css, type Interpolation, type Theme } from "@emotion/react"; | ||
const useFileDrop = ( | ||
callback: (file: File) => void, | ||
@@ -62,7 +61,6 @@ export const FileUpload: FC<FileUploadProps> = ({ | ||
extension, | ||
fileTypeRequired, | ||
}) => { | ||
const inputRef = useRef<HTMLInputElement>(null); | ||
const tarDrop = useFileDrop(onUpload, fileTypeRequired); | ||
@@ -75,7 +73,7 @@ export const FileUpload: FC<FileUploadProps> = ({ | ||
if (!isUploading && file) { | ||
return ( | ||
<Stack | ||
css={styles.file} | ||
direction="row" | ||
justifyContent="space-between" | ||
alignItems="center" | ||
@@ -95,23 +93,20 @@ export const FileUpload: FC<FileUploadProps> = ({ | ||
return ( | ||
<> | ||
<div | ||
css={[styles.root, isUploading && styles.disabled]} | ||
{...clickable} | ||
{...tarDrop} | ||
> | ||
<Stack alignItems="center" spacing={1}> | ||
{isUploading ? ( | ||
<CircularProgress size={32} /> | ||
) : ( | ||
<UploadIconcss={styles.icon} /> | ||
)} | ||
<Stack alignItems="center" spacing={0.5}> | ||
<spancss={styles.title}>{title}</span> | ||
<spancss={styles.description}>{description}</span> | ||
</Stack> | ||
</Stack> | ||
</div> | ||
@@ -120,7 +115,7 @@ export const FileUpload: FC<FileUploadProps> = ({ | ||
type="file" | ||
data-testid="file-upload" | ||
ref={inputRef} | ||
css={styles.input} | ||
accept={extension} | ||
onChange={(event) => { | ||
const file = event.currentTarget.files?.[0]; | ||
@@ -133,48 +128,48 @@ export const FileUpload: FC<FileUploadProps> = ({ | ||
); | ||
}; | ||
conststyles = { | ||
root:(theme) => css` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Just a question for my own understanding: is there a difference between an interpolation function returning an object, vs a tagged css template literal? Is the main use case to enable the conststyles={"&:hover":(theme)=>({ background-color:${theme.palette.background.paper};})}; | ||
display: flex; | ||
align-items:center; | ||
justify-content:center; | ||
border-radius: ${theme.shape.borderRadius}px; | ||
border: 2px dashed ${theme.palette.divider}; | ||
padding:${theme.spacing(6)}; | ||
cursor: pointer; | ||
&:hover { | ||
background-color: ${theme.palette.background.paper}; | ||
} | ||
`, | ||
disabled: { | ||
pointerEvents: "none", | ||
opacity: 0.75, | ||
}, | ||
icon:(theme) => ({ | ||
fontSize: theme.spacing(8), | ||
}), | ||
title:(theme) => ({ | ||
fontSize: theme.spacing(2), | ||
}), | ||
description:(theme) => ({ | ||
color: theme.palette.text.secondary, | ||
textAlign: "center", | ||
maxWidth: theme.spacing(50), | ||
}), | ||
input: { | ||
display: "none", | ||
}, | ||
file:(theme) => ({ | ||
borderRadius: theme.shape.borderRadius, | ||
border: `1px solid ${theme.palette.divider}`, | ||
padding: theme.spacing(2), | ||
background: theme.palette.background.paper, | ||
}), | ||
} satisfies Record<string, Interpolation<Theme>>; |
Uh oh!
There was an error while loading.Please reload this page.