Add more info to NC Mall section of Item Getting Guide

NC prices, some CSS, and also a new application-level helper that adds
a feature I've long wanted and been working around for Turbo: the
ability to specific that a stylesheet is specific to the current page,
and should be unloaded when removed!

I use this to write `sources.sass` without the usual
`body.items-sources` scoping that we've historically used to control
what pages a stylesheet applies to. (In the long past, this was because
a lot of stylesheets were—and still are–routed through the
`application.sass` stylesheet! But even for more recent standalone page
stylesheets, I've done the scoping, to avoid issues with styles leaking
beyond the page they're meant for when Turbo does a navigation.)
This commit is contained in:
Emi Matchu 2024-05-14 16:03:35 -07:00
parent d3b3a3060c
commit d8b577aab1
5 changed files with 43 additions and 1 deletions

View file

@ -0,0 +1,14 @@
.nc-mall-items
list-style: none
display: flex
flex-wrap: wrap
gap: 1em
li
display: flex
flex-direction: column
align-items: center
width: auto
.add-to-cart
font-size: 85%

View file

@ -175,6 +175,14 @@ module ApplicationHelper
end
end
# Includes a stylesheet designed for this specific page of the app, which
# should be removed when navigating to another page. We use Turbo's
# `data-turbo-track="dynamic"` option to do this.
def page_stylesheet_link_tag(src, options={})
options = {data: {"turbo-track": "dynamic"}}.deep_merge(options)
stylesheet_link_tag src, options
end
def secondary_nav(&block)
content_for :before_flashes,
content_tag(:nav, :id => 'secondary-nav', &block)

View file

@ -175,6 +175,10 @@ class Item < ApplicationRecord
@wanted || false
end
def current_nc_price
nc_mall_record.current_price
end
def restricted_zones(options={})
options[:scope] ||= Zone.all
options[:scope].find(restricted_zone_ids)

View file

@ -1,3 +1,7 @@
class NCMallRecord < ApplicationRecord
belongs_to :item
def current_price
discount_price || price
end
end

View file

@ -3,7 +3,16 @@
- if @nc_mall_items.present?
%h2 NC Mall items
= render @nc_mall_items
%p
These items are available in the NC Mall right now! You can buy them
with #{link_to "Neocash", "https://secure.nc.neopets.com/get-neocash"},
a special currency you can purchase directly from Neopets or redeem via gift cards.
%ul.nc-mall-items
- @nc_mall_items.each do |item|
%li
= render item
%button.add-to-cart{onclick: "alert('Todo!')"}
Buy (#{item.current_nc_price} NC)
- if @np_items.present?
%h2 Neopoint items
@ -16,3 +25,6 @@
- if @other_nc_items.present?
%h2 Other NC items
= render @other_nc_items
- content_for :stylesheets do
= page_stylesheet_link_tag "items/sources"