Skip to content

Commit 18bbd8e

Browse files
authored
fix(frontend): Fix confetti (#11031)
### Changes ๐Ÿ—๏ธ - Fix not being able to complete `MARKETPLACE_RUN_AGENT` task - Fix confetti shooting on every refresh - Fix confetti shooting from top-left corner ### Checklist ๐Ÿ“‹ #### For code changes: - [x] I have clearly listed my changes in the PR description - [x] I have made a test plan - [x] I have tested my changes according to the test plan: - [x] Bugs eradicated
1 parent 047f011 commit 18bbd8e

File tree

2 files changed

+31
-24
lines changed

2 files changed

+31
-24
lines changed

โ€Žautogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/OldAgentLibraryView/components/agent-run-draft-view.tsxโ€Ž

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ export function AgentRunDraftView({
103103
const [changedPresetAttributes, setChangedPresetAttributes] = useState<
104104
Set<keyof LibraryAgentPresetUpdatable>
105105
>(new Set());
106-
const { state: onboardingState, completeStep: completeOnboardingStep } =
107-
useOnboarding();
106+
const { completeStep: completeOnboardingStep } = useOnboarding();
108107
const [cronScheduleDialogOpen, setCronScheduleDialogOpen] = useState(false);
109108

110109
// Update values if agentPreset parameter is changed
@@ -197,9 +196,7 @@ export function AgentRunDraftView({
197196
.catch(toastOnFail("execute agent preset"));
198197
}
199198
// Mark run agent onboarding step as completed
200-
if (onboardingState?.completedSteps.includes("MARKETPLACE_ADD_AGENT")) {
201-
completeOnboardingStep("MARKETPLACE_RUN_AGENT");
202-
}
199+
completeOnboardingStep("MARKETPLACE_RUN_AGENT");
203200
if (runCount > 0) {
204201
completeOnboardingStep("RE_RUN_AGENT");
205202
}
@@ -210,7 +207,6 @@ export function AgentRunDraftView({
210207
inputCredentials,
211208
onRun,
212209
toastOnFail,
213-
onboardingState,
214210
completeOnboardingStep,
215211
]);
216212

@@ -246,7 +242,6 @@ export function AgentRunDraftView({
246242
onCreatePreset,
247243
toast,
248244
toastOnFail,
249-
onboardingState,
250245
completeOnboardingStep,
251246
]);
252247

@@ -286,7 +281,6 @@ export function AgentRunDraftView({
286281
onUpdatePreset,
287282
toast,
288283
toastOnFail,
289-
onboardingState,
290284
completeOnboardingStep,
291285
]);
292286

@@ -334,7 +328,6 @@ export function AgentRunDraftView({
334328
onCreatePreset,
335329
toast,
336330
toastOnFail,
337-
onboardingState,
338331
completeOnboardingStep,
339332
]);
340333

โ€Žautogpt_platform/frontend/src/components/__legacy__/Wallet.tsxโ€Ž

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -171,21 +171,28 @@ export default function Wallet() {
171171
}, [groups]);
172172

173173
// Get total completed count for all groups
174-
const completedCount = useMemo(() => {
175-
return groups.reduce(
174+
const [completedCount, setCompletedCount] = useState<number | null>(null);
175+
// Needed to show confetti when a new step is completed
176+
const [prevCompletedCount, setPrevCompletedCount] = useState<number | null>(
177+
null,
178+
);
179+
180+
const walletRef = useRef<HTMLButtonElement | null>(null);
181+
182+
useEffect(() => {
183+
if (!state) {
184+
return;
185+
}
186+
const completed = groups.reduce(
176187
(acc, group) =>
177188
acc +
178189
group.tasks.filter((task) => state?.completedSteps?.includes(task.id))
179190
.length,
180191
0,
181192
);
193+
setCompletedCount(completed);
182194
}, [groups, state?.completedSteps]);
183195

184-
// Needed to show confetti when a new step is completed
185-
const [stepsLength, setStepsLength] = useState(completedCount);
186-
187-
const walletRef = useRef<HTMLButtonElement | null>(null);
188-
189196
const onWalletOpen = useCallback(async () => {
190197
if (!state?.walletShown) {
191198
updateState({ walletShown: true });
@@ -206,19 +213,25 @@ export default function Wallet() {
206213

207214
// Confetti effect on the wallet button
208215
useEffect(() => {
209-
if (!state?.completedSteps) {
210-
return;
211-
}
212216
// It's enough to check completed count,
213217
// because the order of completed steps is not important
214218
// If the count is the same, we don't need to do anything
215-
if (completedCount === stepsLength) {
219+
if (completedCount === null || completedCount === prevCompletedCount) {
220+
return;
221+
}
222+
// Otherwise, we need to set the new prevCompletedCount
223+
setPrevCompletedCount(completedCount);
224+
// If there was no previous count, we don't show confetti
225+
if (prevCompletedCount === null) {
216226
return;
217227
}
218-
// Otherwise, we need to set the new length
219-
setStepsLength(completedCount);
220228
// And emit confetti
221229
if (walletRef.current) {
230+
// Fix confetti appearing in the top left corner
231+
const rect = walletRef.current.getBoundingClientRect();
232+
if (rect.width === 0 || rect.height === 0) {
233+
return;
234+
}
222235
setTimeout(() => {
223236
fetchCredits();
224237
party.confetti(walletRef.current!, {
@@ -236,7 +249,8 @@ export default function Wallet() {
236249
state?.notified,
237250
fadeOut,
238251
fetchCredits,
239-
stepsLength,
252+
completedCount,
253+
prevCompletedCount,
240254
walletRef,
241255
]);
242256

@@ -270,7 +284,7 @@ export default function Wallet() {
270284
<span className="text-sm font-semibold">
271285
{formatCredits(credits)}
272286
</span>
273-
{completedCount < totalCount && (
287+
{completedCount && completedCount < totalCount && (
274288
<span className="absolute right-1 top-1 h-2 w-2 rounded-full bg-violet-600"></span>
275289
)}
276290
<div className="absolute bottom-[-2.5rem] left-1/2 z-50 hidden -translate-x-1/2 transform whitespace-nowrap rounded-small bg-white px-4 py-2 shadow-md group-hover:block">

0 commit comments

Comments
ย (0)