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 1 commit
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
Prev Previous commit
Next Next commit
chore: add provider to base Storybook meta
  • Loading branch information
Parkreiner committed Apr 30, 2025
commit ebe8821fa7103b6d5610f937aa2ee5400107a384
2 changes: 1 addition & 1 deletion site/src/hooks/useTimeSync.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ export class TimeSync implements TimeSyncApi {
readonly #createNewDatetime: (prev: Date) => Date;
readonly #setInterval: SetInterval;
readonly #clearInterval: ClearInterval;
readonly #selectionCache: Map<string, unknown>;

#latestDateSnapshot: Date;
#subscriptions: SubscriptionEntry[];
#selectionCache: Map<string, unknown>;
#latestIntervalId: number | undefined;

constructor(options: Partial<TimeSyncInitOptions>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
withDashboardProvider,
withGlobalSnackbar,
withOrganizationSettingsProvider,
withTimeSyncProvider,
} from "testHelpers/storybook";
import type { NotificationsPage } from "./NotificationsPage";

Expand Down Expand Up @@ -214,5 +215,6 @@ export const baseMeta = {
withAuthProvider,
withDashboardProvider,
withOrganizationSettingsProvider,
withTimeSyncProvider,
],
} satisfies Meta<typeof NotificationsPage>;
17 changes: 16 additions & 1 deletion site/src/testHelpers/storybook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import { hasFirstUserKey, meKey } from "api/queries/users";
import type { Entitlements } from "api/typesGenerated";
import { GlobalSnackbar } from "components/GlobalSnackbar/GlobalSnackbar";
import { AuthProvider } from "contexts/auth/AuthProvider";
import { TimeSyncProvider } from "hooks/useTimeSync";
import { DashboardContext } from "modules/dashboard/DashboardProvider";
import { DeploymentConfigContext } from "modules/management/DeploymentConfigProvider";
import { OrganizationSettingsContext } from "modules/management/OrganizationSettingsLayout";
import { permissionChecks } from "modules/permissions";
import type { FC } from "react";
import type { FC, ReactElement } from "react";
import { useQueryClient } from "react-query";
import {
MockAppearanceConfig,
Expand Down Expand Up @@ -156,6 +157,20 @@ export const withGlobalSnackbar = (Story: FC) => (
</>
);

const storyDate = new Date("March 15, 2022");
export const withTimeSyncProvider = (Story: FC): ReactElement => {
return (
<TimeSyncProvider
options={{
initialDatetime: storyDate,
resyncOnNewSubscription: false,
}}
>
<Story />
</TimeSyncProvider>
);
};

export const withOrganizationSettingsProvider = (Story: FC) => {
return (
<OrganizationSettingsContext.Provider
Expand Down
Loading