-
Notifications
You must be signed in to change notification settings - Fork 0
fix(web): display selected provider on initial load #71
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -95,13 +95,32 @@ export default function OfferSelector({ | |
| return allOffers.find(o => o.id === selectedOfferId) || null | ||
| }, [selectedOfferId, allOffers]) | ||
|
|
||
| // Initialize selectors from selected offer | ||
| // Initialize/sync selectors from selected offer | ||
| // This effect handles two cases: | ||
| // 1. Initial mount with a selectedOfferId - wait for offers to load then sync | ||
| // 2. selectedOfferId prop changes externally - sync to new offer | ||
| // We track which offer we've synced to avoid interfering with manual user selection | ||
| const [lastSyncedOfferId, setLastSyncedOfferId] = useState<string | null | undefined>(undefined) | ||
|
|
||
| useEffect(() => { | ||
| if (selectedOffer) { | ||
| setSelectedProviderId(selectedOffer.provider_id) | ||
| setSelectedOfferType(selectedOffer.offer_type) | ||
| // We have a valid offer - sync the selectors if not already synced to this offer | ||
| if (lastSyncedOfferId !== selectedOffer.id) { | ||
| setSelectedProviderId(selectedOffer.provider_id) | ||
| setSelectedOfferType(selectedOffer.offer_type) | ||
| setLastSyncedOfferId(selectedOffer.id) | ||
| } | ||
| } else if (selectedOfferId === null || selectedOfferId === undefined) { | ||
| // Offer was cleared externally - reset selectors | ||
| if (lastSyncedOfferId !== null) { | ||
| setSelectedProviderId(null) | ||
| setSelectedOfferType(null) | ||
| setLastSyncedOfferId(null) | ||
| } | ||
| } | ||
| }, [selectedOffer]) | ||
| // Note: when selectedOfferId is set but selectedOffer is null (offers loading), | ||
| // we wait - the effect will re-run when offers finish loading | ||
| }, [selectedOffer, selectedOfferId, lastSyncedOfferId]) | ||
|
Comment on lines
105
to
+123
|
||
|
|
||
| // Reset offer type when provider changes | ||
| const handleProviderChange = (providerId: string | null) => { | ||
|
|
||
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.
Bug: The condition
lastSyncedOfferId !== nullwill fail to reset selectors whenlastSyncedOfferIdisundefined(its initial state).This can happen on initial render if
selectedOfferIdisnullorundefinedfrom the start. In this case,lastSyncedOfferIdwould beundefined, but the condition checks for!== null, so the reset won't happen.Change the condition to:
Or more concisely: