Skip to content
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 7 commits into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ def create_products_controller
end

def create_home_index_view
template("index.html.erb", "app/views/home/index.html.erb")
if Rails.version.split(".").first.to_i >= 7
template("importmap_index.html.erb", "app/views/home/index.html.erb")
else
template("index.html.erb", "app/views/home/index.html.erb")
end
nelsonwittwer marked this conversation as resolved.
Show resolved Hide resolved
end

def add_home_index_route
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<!DOCTYPE html>
<html lang="<%= I18n.locale %>">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link
rel="stylesheet"
href="https://unpkg.com/@shopify/polaris@4.25.0/styles.min.css"
/>
<% if embedded_app? %> <script type="module">
import "lib/shopify_app"

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 || "");
});
});

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>
<body>
<h2>Products</h2>
<% if embedded_app? %> <div id="products"><br>Loading...</div><% else %>
<ul>
<%% @products.each do |product| %>
<li><%%= link_to product.title, "https://#{@current_shopify_session.shop}/admin/products/#{product.id}", target: "_top" %></li>
<%% end %>
</ul>

<hr>
<% end %>
<h2>Webhooks</h2>

<%% if @webhooks.present? %>
<ul>
<%% @webhooks.each do |webhook| %>
<li><%%= webhook.topic %> : <%%= webhook.address %></li>
<%% end %>
</ul>
<%% else %>
<p>This app has not created any webhooks for this Shop. Add webhooks to your ShopifyApp initializer if you need webhooks</p>
<%% end %>
</body>
</html>