-
Notifications
You must be signed in to change notification settings - Fork 699
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
Generated App doesn't work in Safari/Firefox #1506
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7f8ac74
this seems to work
klenotiw 97cbf31
Merge branch 'main' into klenoitw/generated-app-works-in-all-browsers
klenotiw 19a1169
some refactoring
klenotiw 74c1182
remove other erb file
klenotiw 7cdd793
change bridge to displayProducts
klenotiw 4bcea73
address nits
klenotiw 4096730
Merge branch 'main' into klenoitw/generated-app-works-in-all-browsers
klenotiw 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 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 |
---|---|---|
|
@@ -7,48 +7,54 @@ | |
rel="stylesheet" | ||
href="https://unpkg.com/@shopify/[email protected]/styles.min.css" | ||
/> | ||
<% if embedded_app? %> <script> | ||
document.addEventListener("DOMContentLoaded", async function() { | ||
<% if ShopifyApp.use_importmap? %> | ||
await import("lib/shopify_app") | ||
<% end %> | ||
|
||
var SessionToken = window["app-bridge"].actions.SessionToken | ||
var app = window.app; | ||
<% if embedded_app? %> | ||
<script type="module"> | ||
async function displayProducts() { | ||
var SessionToken = window["app-bridge"].actions.SessionToken | ||
var app = window.app; | ||
|
||
app.dispatch( | ||
SessionToken.request(), | ||
); | ||
|
||
// Save a session token for future requests | ||
window.sessionToken = await new Promise((resolve) => { | ||
app.subscribe(SessionToken.Action.RESPOND, (data) => { | ||
resolve(data.sessionToken || ""); | ||
app.dispatch( | ||
SessionToken.request(), | ||
); | ||
// Save a session token for future requests | ||
window.sessionToken = await new Promise((resolve) => { | ||
app.subscribe(SessionToken.Action.RESPOND, (data) => { | ||
resolve(data.sessionToken || ""); | ||
}); | ||
}); | ||
}); | ||
|
||
var fetchProducts = function() { | ||
var headers = new Headers({ "Authorization": "Bearer " + window.sessionToken }); | ||
return fetch("/products", { headers }) | ||
.then(response => response.json()) | ||
.then(data => { | ||
var products = data.products; | ||
var fetchProducts = function() { | ||
var headers = new Headers({ "Authorization": "Bearer " + window.sessionToken }); | ||
return fetch("/products", { headers }) | ||
.then(response => response.json()) | ||
.then(data => { | ||
var products = data.products; | ||
|
||
if (products === undefined || products.length == 0) { | ||
document.getElementById("products").innerHTML = "<br>No products to display."; | ||
} else { | ||
var list = ""; | ||
products.forEach((product) => { | ||
var link = `<a target="_top" href="https://<%%= @shop_origin %>/admin/products/${product.id}">` | ||
list += "<li>" + link + product.title + "</a></li>"; | ||
}); | ||
document.getElementById("products").innerHTML = "<ul>" + list + "</ul>"; | ||
} | ||
}); | ||
}(); | ||
}); | ||
</script> | ||
<% end %> </head> | ||
if (products === undefined || products.length == 0) { | ||
document.getElementById("products").innerHTML = "<br>No products to display."; | ||
} else { | ||
var list = ""; | ||
products.forEach((product) => { | ||
var link = `<a target="_top" href="https://<%%= @shop_origin %>/admin/products/${product.id}">` | ||
list += "<li>" + link + product.title + "</a></li>"; | ||
}); | ||
document.getElementById("products").innerHTML = "<ul>" + list + "</ul>"; | ||
} | ||
}); | ||
}(); | ||
}; | ||
|
||
<% if ShopifyApp.use_importmap? %> | ||
import "lib/shopify_app" | ||
displayProducts(); | ||
<% else %> | ||
document.addEventListener("DOMContentLoaded", async function() { | ||
displayProducts(); | ||
}); | ||
<% end %> | ||
nelsonwittwer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</script> | ||
<% end %> | ||
</head> | ||
<body> | ||
<h2>Products</h2> | ||
<% if embedded_app? %> <div id="products"><br>Loading...</div><% else %> | ||
|
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.
Can we simplify this?
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.
You are right! I was trying to do this but I was using
displayProducts()
instead ofdisplayProducts
lesson learn lol. Thanks for this!