Skip to content

Commit 24569af

Browse files
committed
countdown
1 parent 9487a57 commit 24569af

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

apps/builder/app/builder/features/topbar/publish.tsx

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,34 @@ const $usedProFeatures = computed(
294294
}
295295
);
296296

297+
const usePublishCountdown = (isPublishing: boolean) => {
298+
const [countdown, setCountdown] = useState<number | undefined>(undefined);
299+
300+
useEffect(() => {
301+
if (isPublishing === false) {
302+
setCountdown(undefined);
303+
return;
304+
}
305+
306+
setCountdown(60);
307+
308+
const interval = setInterval(() => {
309+
setCountdown((prev) => {
310+
if (prev === undefined || prev <= 0) {
311+
return 0;
312+
}
313+
return prev - 1;
314+
});
315+
}, 1000);
316+
317+
return () => {
318+
clearInterval(interval);
319+
};
320+
}, [isPublishing]);
321+
322+
return countdown;
323+
};
324+
297325
const Publish = ({
298326
project,
299327
timesLeft,
@@ -313,6 +341,7 @@ const Publish = ({
313341
const buttonRef = useRef<HTMLButtonElement>(null);
314342
const [hasSelectedDomains, setHasSelectedDomains] = useState(false);
315343
const hasProPlan = useStore($userPlanFeatures).hasProPlan;
344+
const countdown = usePublishCountdown(isPublishing);
316345

317346
useEffect(() => {
318347
if (hasProPlan === false) {
@@ -469,6 +498,8 @@ const Publish = ({
469498
: false;
470499

471500
const isPublishInProgress = isPublishing || hasPendingState;
501+
const showPendingState =
502+
isPublishInProgress && (countdown === undefined || countdown === 0);
472503

473504
return (
474505
<Flex gap={2} shrink={false} direction={"column"}>
@@ -487,10 +518,12 @@ const Publish = ({
487518
ref={buttonRef}
488519
formAction={handlePublish}
489520
color="positive"
490-
state={isPublishInProgress ? "pending" : undefined}
521+
state={showPendingState ? "pending" : undefined}
491522
disabled={hasSelectedDomains === false || disabled}
492523
>
493-
Publish
524+
{countdown !== undefined && countdown > 0
525+
? `Publishing (${countdown}s)`
526+
: "Publish"}
494527
</Button>
495528
</Tooltip>
496529
</Flex>

0 commit comments

Comments
 (0)