-
Notifications
You must be signed in to change notification settings - Fork 579
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(site): Use react-query and refactor the workspaces page to use …
…it (#5838)
- Loading branch information
1 parent
bef9e72
commit 36384aa
Showing
22 changed files
with
499 additions
and
314 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,46 @@ | ||
import CssBaseline from "@material-ui/core/CssBaseline" | ||
import ThemeProvider from "@material-ui/styles/ThemeProvider" | ||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query" | ||
import { AuthProvider } from "components/AuthProvider/AuthProvider" | ||
import { FC } from "react" | ||
import { FC, PropsWithChildren } from "react" | ||
import { HelmetProvider } from "react-helmet-async" | ||
import { AppRouter } from "./AppRouter" | ||
import { ErrorBoundary } from "./components/ErrorBoundary/ErrorBoundary" | ||
import { GlobalSnackbar } from "./components/GlobalSnackbar/GlobalSnackbar" | ||
import { dark } from "./theme" | ||
import "./theme/globalFonts" | ||
|
||
export const App: FC = () => { | ||
const queryClient = new QueryClient({ | ||
defaultOptions: { | ||
queries: { | ||
retry: false, | ||
cacheTime: 0, | ||
}, | ||
}, | ||
}) | ||
|
||
export const AppProviders: FC<PropsWithChildren> = ({ children }) => { | ||
return ( | ||
<HelmetProvider> | ||
<ThemeProvider theme={dark}> | ||
<CssBaseline /> | ||
<ErrorBoundary> | ||
<AuthProvider> | ||
<AppRouter /> | ||
<GlobalSnackbar /> | ||
</AuthProvider> | ||
<QueryClientProvider client={queryClient}> | ||
<AuthProvider> | ||
{children} | ||
<GlobalSnackbar /> | ||
</AuthProvider> | ||
</QueryClientProvider> | ||
</ErrorBoundary> | ||
</ThemeProvider> | ||
</HelmetProvider> | ||
) | ||
} | ||
|
||
export const App: FC = () => { | ||
return ( | ||
<AppProviders> | ||
<AppRouter /> | ||
</AppProviders> | ||
) | ||
} |
104 changes: 104 additions & 0 deletions
104
site/src/components/PaginationWidget/PaginationWidgetBase.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import Button from "@material-ui/core/Button" | ||
import { makeStyles, useTheme } from "@material-ui/core/styles" | ||
import useMediaQuery from "@material-ui/core/useMediaQuery" | ||
import KeyboardArrowLeft from "@material-ui/icons/KeyboardArrowLeft" | ||
import KeyboardArrowRight from "@material-ui/icons/KeyboardArrowRight" | ||
import { ChooseOne, Cond } from "components/Conditionals/ChooseOne" | ||
import { PageButton } from "./PageButton" | ||
import { buildPagedList } from "./utils" | ||
|
||
export type PaginationWidgetBaseProps = { | ||
count: number | ||
page: number | ||
limit: number | ||
onChange: (page: number) => void | ||
} | ||
|
||
export const PaginationWidgetBase = ({ | ||
count, | ||
page, | ||
limit, | ||
onChange, | ||
}: PaginationWidgetBaseProps): JSX.Element | null => { | ||
const theme = useTheme() | ||
const isMobile = useMediaQuery(theme.breakpoints.down("sm")) | ||
const styles = useStyles() | ||
const numPages = Math.ceil(count / limit) | ||
const isFirstPage = page === 0 | ||
const isLastPage = page === numPages - 1 | ||
|
||
if (numPages < 2) { | ||
return null | ||
} | ||
|
||
return ( | ||
<div className={styles.defaultContainerStyles}> | ||
<Button | ||
className={styles.prevLabelStyles} | ||
aria-label="Previous page" | ||
disabled={isFirstPage} | ||
onClick={() => { | ||
if (!isFirstPage) { | ||
onChange(page - 1) | ||
} | ||
}} | ||
> | ||
<KeyboardArrowLeft /> | ||
</Button> | ||
<ChooseOne> | ||
<Cond condition={isMobile}> | ||
<PageButton activePage={page} page={page} numPages={numPages} /> | ||
</Cond> | ||
<Cond> | ||
{buildPagedList(numPages, page).map((pageItem) => { | ||
if (pageItem === "left" || pageItem === "right") { | ||
return ( | ||
<PageButton | ||
key={pageItem} | ||
activePage={page} | ||
placeholder="..." | ||
disabled | ||
/> | ||
) | ||
} | ||
|
||
return ( | ||
<PageButton | ||
key={pageItem} | ||
page={pageItem} | ||
activePage={page} | ||
numPages={numPages} | ||
onPageClick={() => onChange(pageItem)} | ||
/> | ||
) | ||
})} | ||
</Cond> | ||
</ChooseOne> | ||
<Button | ||
aria-label="Next page" | ||
disabled={isLastPage} | ||
onClick={() => { | ||
if (!isLastPage) { | ||
onChange(page + 1) | ||
} | ||
}} | ||
> | ||
<KeyboardArrowRight /> | ||
</Button> | ||
</div> | ||
) | ||
} | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
defaultContainerStyles: { | ||
justifyContent: "center", | ||
alignItems: "center", | ||
display: "flex", | ||
flexDirection: "row", | ||
padding: "20px", | ||
}, | ||
|
||
prevLabelStyles: { | ||
marginRight: `${theme.spacing(0.5)}px`, | ||
}, | ||
})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.