Skip to content

Commit 18b8ec1

Browse files
committed
Use minutes when selecting refresh rate
1 parent 1d612b0 commit 18b8ec1

1 file changed

Lines changed: 25 additions & 12 deletions

File tree

  • services/backend-api/client/src/features/feedConnections/components/UserFeedMiscSettingsTabSection

services/backend-api/client/src/features/feedConnections/components/UserFeedMiscSettingsTabSection/index.tsx

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ const FormSchema = object({
111111
.optional()
112112
.nullable()
113113
.default(null),
114-
userRefreshRateSeconds: number().optional(),
114+
userRefreshRateMinutes: string().optional(),
115115
});
116116

117117
type FormValues = InferType<typeof FormSchema>;
@@ -142,7 +142,10 @@ export const UserFeedMiscSettingsTabSection = ({ feedId }: Props) => {
142142
dateLocale: feed?.formatOptions?.dateLocale || "",
143143
oldArticleDateDiffMsThreshold: feed?.dateCheckOptions?.oldArticleDateDiffMsThreshold || 0,
144144
shareManageOptions: feed?.shareManageOptions || null,
145-
userRefreshRateSeconds: feed?.userRefreshRateSeconds || feed?.refreshRateSeconds,
145+
userRefreshRateMinutes:
146+
(
147+
Number((feed?.userRefreshRateSeconds || feed?.refreshRateSeconds || 0).toFixed(1)) / 60
148+
)?.toString() || "",
146149
},
147150
});
148151
const {
@@ -190,6 +193,9 @@ export const UserFeedMiscSettingsTabSection = ({ feedId }: Props) => {
190193

191194
const onUpdatedFeed = async (values: FormValues) => {
192195
try {
196+
const userRefreshRateMinutesInSeconds = !Number.isNaN(values.userRefreshRateMinutes)
197+
? Number(values.userRefreshRateMinutes) * 60
198+
: undefined;
193199
const updatedFeed = await mutateAsync({
194200
feedId,
195201
data: {
@@ -206,7 +212,7 @@ export const UserFeedMiscSettingsTabSection = ({ feedId }: Props) => {
206212
oldArticleDateDiffMsThreshold: values.oldArticleDateDiffMsThreshold,
207213
}
208214
: undefined,
209-
userRefreshRateSeconds: values.userRefreshRateSeconds || undefined,
215+
userRefreshRateSeconds: userRefreshRateMinutesInSeconds,
210216
},
211217
});
212218

@@ -217,8 +223,11 @@ export const UserFeedMiscSettingsTabSection = ({ feedId }: Props) => {
217223
oldArticleDateDiffMsThreshold:
218224
updatedFeed.result.dateCheckOptions?.oldArticleDateDiffMsThreshold,
219225
shareManageOptions: updatedFeed.result.shareManageOptions || null,
220-
userRefreshRateSeconds:
221-
updatedFeed.result.userRefreshRateSeconds || updatedFeed.result.refreshRateSeconds,
226+
userRefreshRateMinutes:
227+
updatedFeed.result.userRefreshRateSeconds &&
228+
!Number.isNaN(updatedFeed.result.userRefreshRateSeconds)
229+
? (updatedFeed.result.userRefreshRateSeconds / 60).toFixed(1)
230+
: (updatedFeed.result.refreshRateSeconds / 60).toFixed(1),
222231
});
223232
createSuccessAlert({
224233
title: "Successfully updated feed settings",
@@ -231,7 +240,9 @@ export const UserFeedMiscSettingsTabSection = ({ feedId }: Props) => {
231240
if (e instanceof ApiAdapterError && e.errorCode === "USER_REFRESH_RATE_NOT_ALLOWED") {
232241
createErrorAlert({
233242
title: "Refresh rate is not allowed.",
234-
description: `Your selected refresh rate must be greater than or equal to ${fastestAllowedRate} and less than or equal to 86400 seconds (1 day).`,
243+
description: `Your selected refresh rate must be greater than or equal to ${(
244+
fastestAllowedRate / 60
245+
).toFixed(1)} minutes and less than or equal to 1440.0 minutes (1 day).`,
235246
});
236247
} else {
237248
createErrorAlert({
@@ -520,7 +531,7 @@ export const UserFeedMiscSettingsTabSection = ({ feedId }: Props) => {
520531
)}
521532
{!!feed?.refreshRateOptions.length && (
522533
<Controller
523-
name="userRefreshRateSeconds"
534+
name="userRefreshRateMinutes"
524535
control={control}
525536
render={({ field }) => {
526537
return (
@@ -531,9 +542,11 @@ export const UserFeedMiscSettingsTabSection = ({ feedId }: Props) => {
531542
<HStack alignItems="center" spacing={4}>
532543
<NumberInput
533544
allowMouseWheel
534-
value={field.value === null ? "" : field.value}
545+
precision={1}
546+
step={0.1}
547+
value={field.value}
535548
onChange={(str, num) => {
536-
return Number.isNaN(num) ? field.onChange(null) : field.onChange(num);
549+
return field.onChange(str);
537550
}}
538551
onBlur={() => field.onBlur()}
539552
isDisabled={!user || field.disabled}
@@ -546,11 +559,11 @@ export const UserFeedMiscSettingsTabSection = ({ feedId }: Props) => {
546559
<NumberDecrementStepper />
547560
</NumberInputStepper>
548561
</NumberInput>
549-
<FormLabel>seconds</FormLabel>
562+
<FormLabel>minutes</FormLabel>
550563
</HStack>
551-
{formErrors.userRefreshRateSeconds && (
564+
{formErrors.userRefreshRateMinutes && (
552565
<FormErrorMessage>
553-
{formErrors.userRefreshRateSeconds.message}
566+
{formErrors.userRefreshRateMinutes.message}
554567
</FormErrorMessage>
555568
)}
556569
</FormControl>

0 commit comments

Comments
 (0)