Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d0a57de

Browse files
committed
docs: add more info about properties
1 parent 997c3da commit d0a57de

File tree

9 files changed

+36
-12
lines changed

9 files changed

+36
-12
lines changed

site/src/components/SignInLayout/SignInLayout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { FC, PropsWithChildren } from "react";
44

55
export const SignInLayout: FC<PropsWithChildren> = ({ children }) => {
66
const year = useTimeSync({
7-
idealRefreshIntervalMs: Number.POSITIVE_INFINITY,
7+
targetRefreshInterval: Number.POSITIVE_INFINITY,
88
select: (date) => date.getFullYear(),
99
});
1010

site/src/hooks/useTimeSync.tsx

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,28 @@ export const TimeSyncProvider: FC<TimeSyncProviderProps> = ({
158158
};
159159

160160
type UseTimeSyncOptions<T = Date> = Readonly<{
161-
idealRefreshIntervalMs: number;
162-
selectDeps?: readonly unknown[];
161+
/**
162+
* targetRefreshInterval is the ideal interval of time, in milliseconds,
163+
* that defines how often the hook should refresh with the newest Date
164+
* value from TimeSync.
165+
*
166+
* Note that a refresh is not the same as a re-render. If the hook is
167+
* refreshed with a new datetime, but its select callback produces the same
168+
* value as before, the hook will skip re-rendering.
169+
*
170+
* The hook reserves the right to refresh MORE frequently than the
171+
* specified value if it would guarantee that the hook does not get out of
172+
* sync with other useTimeSync users that are currently mounted on screen.
173+
*/
174+
targetRefreshInterval: number;
175+
176+
/**
177+
* selectDependencies acts like the dependency array for a useMemo callback.
178+
* Whenever any of the elements in the array change by value, that will
179+
* cause the select callback to re-run synchronously and produce a new,
180+
* up-to-date value for the current render.
181+
*/
182+
selectDependencies?: readonly unknown[];
163183

164184
/**
165185
* Allows you to transform any date values received from the TimeSync class.
@@ -189,7 +209,11 @@ type UseTimeSyncOptions<T = Date> = Readonly<{
189209
* interval.
190210
*/
191211
export function useTimeSync<T = Date>(options: UseTimeSyncOptions<T>): T {
192-
const { select, selectDeps, idealRefreshIntervalMs } = options;
212+
const {
213+
select,
214+
selectDependencies: selectDeps,
215+
targetRefreshInterval: idealRefreshIntervalMs,
216+
} = options;
193217
const timeSync = useContext(timeSyncContext);
194218
if (timeSync === null) {
195219
throw new Error("Cannot call useTimeSync outside of a TimeSyncProvider");

site/src/pages/CliInstallPage/CliInstallPageView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type CliInstallPageViewProps = {
1111

1212
export const CliInstallPageView: FC<CliInstallPageViewProps> = ({ origin }) => {
1313
const year = useTimeSync({
14-
idealRefreshIntervalMs: Number.POSITIVE_INFINITY,
14+
targetRefreshInterval: Number.POSITIVE_INFINITY,
1515
select: (date) => date.getFullYear(),
1616
});
1717

site/src/pages/DeploymentSettingsPage/LicensesSettingsPage/LicenseCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const LicenseCard: FC<LicenseCardProps> = ({
2525
onRemove,
2626
isRemoving,
2727
}) => {
28-
const time = useTimeSync({ idealRefreshIntervalMs: 30_000 });
28+
const time = useTimeSync({ targetRefreshInterval: 30_000 });
2929
const [licenseIDMarkedForRemoval, setLicenseIDMarkedForRemoval] = useState<
3030
number | undefined
3131
>(undefined);

site/src/pages/LoginPage/LoginPageView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const LoginPageView: FC<LoginPageViewProps> = ({
2929
redirectTo,
3030
}) => {
3131
const year = useTimeSync({
32-
idealRefreshIntervalMs: Number.POSITIVE_INFINITY,
32+
targetRefreshInterval: Number.POSITIVE_INFINITY,
3333
select: (date) => date.getFullYear(),
3434
});
3535
const location = useLocation();

site/src/pages/TemplatePage/TemplateInsightsPage/DateRange.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ interface DateRangeProps {
4444

4545
export const DateRange: FC<DateRangeProps> = ({ value, onChange }) => {
4646
const currentTime = useTimeSync({
47-
idealRefreshIntervalMs: IDEAL_REFRESH_ONE_MINUTE,
47+
targetRefreshInterval: IDEAL_REFRESH_ONE_MINUTE,
4848
});
4949
const selectionStatusRef = useRef<"idle" | "selecting">("idle");
5050
const [ranges, setRanges] = useState<RangesState>([

site/src/pages/TemplatePage/TemplateInsightsPage/TemplateInsightsPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ export default function TemplateInsightsPage() {
7171

7272
const paramsInterval = searchParams.get("interval");
7373
const insightsInterval = useTimeSync<InsightsInterval>({
74-
idealRefreshIntervalMs: IDEAL_REFRESH_ONE_DAY,
75-
selectDeps: [paramsInterval],
74+
targetRefreshInterval: IDEAL_REFRESH_ONE_DAY,
75+
selectDependencies: [paramsInterval],
7676
select: (newDate) => {
7777
const templateCreateDate = new Date(template.created_at);
7878
const hasFiveWeeksOrMore = addWeeks(templateCreateDate, 5) < newDate;

site/src/pages/WorkspacePage/AppStatuses.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export const AppStatuses: FC<AppStatusesProps> = ({
154154
referenceDate,
155155
}) => {
156156
const comparisonDate = useTimeSync({
157-
idealRefreshIntervalMs: IDEAL_REFRESH_ONE_MINUTE,
157+
targetRefreshInterval: IDEAL_REFRESH_ONE_MINUTE,
158158
select: (dateState) => referenceDate ?? dateState,
159159
});
160160
const theme = useTheme();

site/src/pages/WorkspacePage/WorkspaceScheduleControls.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ const AutostopDisplay: FC<AutostopDisplayProps> = ({
163163
};
164164

165165
const activityStatus = useTimeSync({
166-
idealRefreshIntervalMs: 1_000,
166+
targetRefreshInterval: 1_000,
167167
select: () => getWorkspaceActivityStatus(workspace),
168168
});
169169
const { message, tooltip, danger } = autostopDisplay(

0 commit comments

Comments
 (0)