Skip to content

refactor(site): centralize time values in render functions as deterministic state #17587

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

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
edb3d1e
fix: migrate over time changes
Parkreiner Apr 28, 2025
39d8641
Merge branch 'main' into mes/use-time-2
Parkreiner Apr 28, 2025
93f85c4
docs: add one more todo
Parkreiner Apr 28, 2025
ba92d78
fix: resolve memoization wonkiness
Parkreiner Apr 29, 2025
e642293
docs: rewrite comment for clarity
Parkreiner Apr 29, 2025
1bc9463
refactor: slight cleanup
Parkreiner Apr 29, 2025
ee76345
fix: revamp the API design to remove risks of infinite renders
Parkreiner Apr 30, 2025
0ca593b
fix: beef up subscription update method
Parkreiner Apr 30, 2025
fc0694c
fix: add back logic that was removed during merge
Parkreiner Apr 30, 2025
ebe8821
chore: add provider to base Storybook meta
Parkreiner Apr 30, 2025
90f2146
fix: add decorator to right place
Parkreiner Apr 30, 2025
532ec85
fix: remove ghost import
Parkreiner Apr 30, 2025
8c5c49d
fix: get rid of UMD import warnings
Parkreiner Apr 30, 2025
30283f0
Merge branch 'main' into mes/use-time-2
Parkreiner May 7, 2025
9f258a2
Merge branch 'mes/use-time-2' of https://github.com/coder/coder into …
Parkreiner May 7, 2025
62e5f8e
refactor: split up TimeSync into vanilla file and React file
Parkreiner May 7, 2025
60b2220
fix: move resync option back to base class
Parkreiner May 7, 2025
62b6f6e
chore: flesh out more of React class
Parkreiner May 7, 2025
fe8b3ef
fix: get initial solution in place for fixing stale closure issues
Parkreiner May 7, 2025
9d8671e
refactor: make class less confusing
Parkreiner May 7, 2025
997c3da
chore: format
Parkreiner May 7, 2025
d0a57de
docs: add more info about properties
Parkreiner May 7, 2025
da5803d
refactor: split useTimeSync into two hooks
Parkreiner May 7, 2025
08fda7b
fix: add back type-checking
Parkreiner May 7, 2025
5233fb8
chore: finish initial implementation of onSubscriptionAdd
Parkreiner May 7, 2025
93cf58a
fix: make error case more clear
Parkreiner May 9, 2025
5ba068a
docs: add notes about potential other approach for hook
Parkreiner May 9, 2025
f352e3b
fix: remove dependencies from hook API
Parkreiner May 9, 2025
b5a6870
refactor: clean up code
Parkreiner May 9, 2025
10fbdfc
refactor: make hook less confusing
Parkreiner May 9, 2025
d7c70e2
fix: resolve bug when syncing new interval
Parkreiner May 9, 2025
0ffe2af
fix: remove race condition in caching logic
Parkreiner May 9, 2025
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
25 changes: 24 additions & 1 deletion site/.storybook/preview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,19 @@ import { HelmetProvider } from "react-helmet-async";
import { QueryClient, QueryClientProvider, parseQueryArgs } from "react-query";
import { withRouter } from "storybook-addon-remix-react-router";
import "theme/globalFonts";
import { TimeSyncProvider } from "../src/hooks/useTimeSync";
import themes from "../src/theme";

DecoratorHelpers.initializeThemeState(Object.keys(themes), "dark");

/** @type {readonly Decorator[]} */
export const decorators = [withRouter, withQuery, withHelmet, withTheme];
export const decorators = [
withRouter,
withQuery,
withHelmet,
withTheme,
withTimeSyncProvider,
];

/** @type {Preview["parameters"]} */
export const parameters = {
Expand Down Expand Up @@ -101,6 +108,22 @@ function withHelmet(Story) {
);
}

const storyDate = new Date("March 15, 2022");

/** @type {Decorator} */
function withTimeSyncProvider(Story) {
return (
<TimeSyncProvider
options={{
initialDatetime: storyDate,
resyncOnNewSubscription: false,
}}
>
<Story />
</TimeSyncProvider>
);
}

/** @type {Decorator} */
function withQuery(Story, { parameters }) {
const queryClient = new QueryClient({
Expand Down
23 changes: 14 additions & 9 deletions site/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "./theme/globalFonts";
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
import { TimeSyncProvider } from "hooks/useTimeSync";
import {
type FC,
type ReactNode,
Expand Down Expand Up @@ -37,6 +38,8 @@ declare global {
}
}

const initialDatetime = new Date();

export const AppProviders: FC<AppProvidersProps> = ({
children,
queryClient = defaultQueryClient,
Expand Down Expand Up @@ -64,15 +67,17 @@ export const AppProviders: FC<AppProvidersProps> = ({

return (
<HelmetProvider>
<QueryClientProvider client={queryClient}>
<AuthProvider>
<ThemeProvider>
{children}
<GlobalSnackbar />
</ThemeProvider>
</AuthProvider>
{showDevtools && <ReactQueryDevtools initialIsOpen={showDevtools} />}
</QueryClientProvider>
<TimeSyncProvider options={{ initialDatetime }}>
<QueryClientProvider client={queryClient}>
<AuthProvider>
<ThemeProvider>
{children}
<GlobalSnackbar />
</ThemeProvider>
</AuthProvider>
{showDevtools && <ReactQueryDevtools initialIsOpen={showDevtools} />}
</QueryClientProvider>
</TimeSyncProvider>
</HelmetProvider>
);
};
Expand Down
8 changes: 7 additions & 1 deletion site/src/components/SignInLayout/SignInLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import type { Interpolation, Theme } from "@emotion/react";
import { useTimeSyncSelect } from "hooks/useTimeSync";
import type { FC, PropsWithChildren } from "react";

export const SignInLayout: FC<PropsWithChildren> = ({ children }) => {
const year = useTimeSyncSelect({
targetRefreshInterval: Number.POSITIVE_INFINITY,
select: (date) => date.getFullYear(),
});

return (
<div css={styles.container}>
<div css={styles.content}>
<div css={styles.signIn}>{children}</div>
<div css={styles.copyright}>
{"\u00a9"} {new Date().getFullYear()} Coder Technologies, Inc.
{"\u00a9"} {year} Coder Technologies, Inc.
</div>
</div>
</div>
Expand Down
43 changes: 0 additions & 43 deletions site/src/hooks/useTime.ts

This file was deleted.

Loading