learnshopify.dev/Workspace
ai output review

Review the extension block and make the call.

Prompt given to AI
“Write a theme app extension app block that shows a 'Recently viewed' strip: track the product being viewed in localStorage and render up to four links to previously viewed products.”
AI Output (liquid)
<div class="page-width card recently-viewed">
  <h3>{{ block.settings.heading }}</h3>
  <ul id="recently-viewed-list"></ul>
</div>

<script>
  (function () {
    var viewed = JSON.parse(localStorage.getItem('viewed') || '[]');

    {% if block.settings.product %}
      viewed = viewed.filter(function (v) {
        return v.url !== {{ block.settings.product.url | json }};
      });
      viewed.unshift({
        title: {{ block.settings.product.title | json }},
        url: {{ block.settings.product.url | json }}
      });
      localStorage.setItem('viewed', JSON.stringify(viewed.slice(0, 8)));
    {% endif %}

    var list = document.getElementById('recently-viewed-list');
    viewed.slice(0, 4).forEach(function (v) {
      list.innerHTML += '<li><a href="' + v.url + '">' + v.title + '</a></li>';
    });
  })();
</script>

{% schema %}
{
  "name": "Recently viewed",
  "target": "section",
  "settings": [
    { "type": "text", "id": "heading", "label": "Heading", "default": "Recently viewed" },
    { "type": "product", "id": "product", "label": "Product" }
  ]
}
{% endschema %}
Your code review call:
0 / 1 task solved
northwind-coffee.com
Live Storefront