-
Notifications
You must be signed in to change notification settings - Fork 61
Save Theme Button After Change Won't Work #282
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
Open
harshvardhan60792
wants to merge
1
commit into
MultiboxLabs:main
Choose a base branch
from
harshvardhan60792:fix/281-save-theme-button-after-change-won-t-wor
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import { useState } from "react"; | ||
| import { useRef, useState } from "react"; | ||
| import { Button } from "@/components/ui/button"; | ||
| import { ArrowLeft, Loader2, Save, Settings, Trash2, PaintBucket, Check } from "lucide-react"; | ||
| import type { Space } from "~/flow/interfaces/sessions/spaces"; | ||
|
|
@@ -23,10 +23,17 @@ export function SpaceEditor({ space, onClose, onDelete, onSpacesUpdate }: SpaceE | |
| const [saveSuccess, setSaveSuccess] = useState(false); | ||
| const [deleteDialogOpen, setDeleteDialogOpen] = useState(false); | ||
| const [isDeleting, setIsDeleting] = useState(false); | ||
| // Tracks the latest saveSuccess value for the auto-close timeout below, | ||
| // since a setTimeout closure only ever sees the state at the time it was scheduled. | ||
| const saveSuccessRef = useRef(false); | ||
|
|
||
| // Update edited space | ||
| const updateEditedSpace = (updates: Partial<Space>) => { | ||
| setEditedSpace((prev) => ({ ...prev, ...updates })); | ||
| // A fresh edit invalidates the previous "Saved" confirmation so the Save | ||
| // button becomes clickable again instead of staying stuck on "Saved". | ||
| saveSuccessRef.current = false; | ||
| setSaveSuccess(false); | ||
| }; | ||
|
|
||
| // Handle space update | ||
|
|
@@ -58,11 +65,12 @@ export function SpaceEditor({ space, onClose, onDelete, onSpacesUpdate }: SpaceE | |
|
|
||
| await flow.spaces.updateSpace(space.profileId, space.id, updatedFields); | ||
| onSpacesUpdate(); // Refetch spaces after successful update | ||
| saveSuccessRef.current = true; | ||
| setSaveSuccess(true); | ||
|
|
||
| // Auto-close after short delay | ||
| // Auto-close after short delay, unless the user started editing again in the meantime | ||
| setTimeout(() => { | ||
| if (saveSuccess) { | ||
| if (saveSuccessRef.current) { | ||
| onClose(); | ||
| } | ||
|
Comment on lines
+73
to
75
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| }, 1500); | ||
|
|
@@ -97,6 +105,9 @@ export function SpaceEditor({ space, onClose, onDelete, onSpacesUpdate }: SpaceE | |
| ...editedSpace, | ||
| name: e.target.value | ||
| }); | ||
| // See updateEditedSpace: a fresh edit should re-enable the Save button. | ||
| saveSuccessRef.current = false; | ||
| setSaveSuccess(false); | ||
| }; | ||
|
|
||
| // Detect if there are unsaved changes | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Do not let an older save overwrite a newer edit.
If the user edits the space while
flow.spaces.updateSpace(...)is pending, Lines 35 or 109 setsaveSuccessRef.currenttofalse. When the request resolves, Line 68 unconditionally sets it back totrue, and Lines 72-73 can callonClose()whileeditedSpacecontains unsaved changes.The shared boolean also does not identify which save owns the timeout. A timeout from an earlier save can observe
truefrom a later save and close the editor too early.Capture an edit generation when
handleSavestarts. Increment it in both edit handlers. Apply the success state and close only when the captured generation still matches.Proposed fix
🤖 Prompt for AI Agents