forked from maybe-finance/maybe
-
Notifications
You must be signed in to change notification settings - Fork 97
Lunchflow fix #307
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
Merged
Merged
Lunchflow fix #307
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
58adf90
Fix lunch flow pre-loading and UX
sokie 8ca7a12
Small UX fixes
sokie 0aab417
Review comments
sokie d30bed5
Fix json error
sokie d1cdb0c
Delete .claude/settings.local.json
sokie 7693daf
Lunch Flow brand (again :-)
jjmata 9555a4d
FIX process only linked accounts
sokie 4bb5066
FIX disable accounts with no name
sokie daeebfa
Fix string normalization
sokie 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
Some comments aren't visible on the classic Files Changed page.
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
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
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
89 changes: 89 additions & 0 deletions
89
app/javascript/controllers/lunchflow_preload_controller.js
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 |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| import { Controller } from "@hotwired/stimulus"; | ||
|
|
||
| // Connects to data-controller="lunchflow-preload" | ||
| export default class extends Controller { | ||
| static targets = ["link", "spinner"]; | ||
| static values = { | ||
| accountableType: String, | ||
| returnTo: String, | ||
| }; | ||
|
|
||
| connect() { | ||
| this.preloadAccounts(); | ||
| } | ||
|
|
||
| async preloadAccounts() { | ||
| try { | ||
| // Show loading state if we have a link target (on method selector page) | ||
| if (this.hasLinkTarget) { | ||
| this.showLoading(); | ||
| } | ||
|
|
||
| // Fetch accounts in background to populate cache | ||
| const url = new URL( | ||
| "/lunchflow_items/preload_accounts", | ||
| window.location.origin | ||
| ); | ||
| if (this.hasAccountableTypeValue) { | ||
| url.searchParams.append("accountable_type", this.accountableTypeValue); | ||
| } | ||
| if (this.hasReturnToValue) { | ||
| url.searchParams.append("return_to", this.returnToValue); | ||
| } | ||
|
|
||
| const csrfToken = document.querySelector('[name="csrf-token"]'); | ||
| const headers = { | ||
| Accept: "application/json", | ||
| }; | ||
| if (csrfToken) { | ||
| headers["X-CSRF-Token"] = csrfToken.content; | ||
| } | ||
|
|
||
| const response = await fetch(url, { headers }); | ||
|
|
||
| if (!response.ok) { | ||
| throw new Error(`HTTP error! status: ${response.status}`); | ||
| } | ||
|
|
||
| const data = await response.json(); | ||
|
|
||
| if (data.success && data.has_accounts) { | ||
| // Accounts loaded successfully, enable the link | ||
| if (this.hasLinkTarget) { | ||
| this.hideLoading(); | ||
| } | ||
| } else if (!data.has_accounts) { | ||
| // No accounts available, hide the link entirely | ||
| if (this.hasLinkTarget) { | ||
| this.linkTarget.style.display = "none"; | ||
| } | ||
| } else { | ||
| // Error occurred | ||
| if (this.hasLinkTarget) { | ||
| this.hideLoading(); | ||
| } | ||
| console.error("Failed to preload Lunchflow accounts:", data.error); | ||
| } | ||
| } catch (error) { | ||
| // On error, still enable the link so user can try | ||
| if (this.hasLinkTarget) { | ||
| this.hideLoading(); | ||
| } | ||
| console.error("Error preloading Lunchflow accounts:", error); | ||
| } | ||
| } | ||
|
|
||
| showLoading() { | ||
| this.linkTarget.classList.add("pointer-events-none", "opacity-50"); | ||
| if (this.hasSpinnerTarget) { | ||
| this.spinnerTarget.classList.remove("hidden"); | ||
| } | ||
| } | ||
|
|
||
| hideLoading() { | ||
| this.linkTarget.classList.remove("pointer-events-none", "opacity-50"); | ||
| if (this.hasSpinnerTarget) { | ||
| this.spinnerTarget.classList.add("hidden"); | ||
| } | ||
| } | ||
sokie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.