diff --git a/app/assets/stylesheets/items/sources.sass b/app/assets/stylesheets/items/sources.sass new file mode 100644 index 00000000..2bb97224 --- /dev/null +++ b/app/assets/stylesheets/items/sources.sass @@ -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% diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 587e020d..0db3a801 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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) diff --git a/app/models/item.rb b/app/models/item.rb index 49b9c3c9..e5295be1 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -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) diff --git a/app/models/nc_mall_record.rb b/app/models/nc_mall_record.rb index 657e7379..d21d1075 100644 --- a/app/models/nc_mall_record.rb +++ b/app/models/nc_mall_record.rb @@ -1,3 +1,7 @@ class NCMallRecord < ApplicationRecord belongs_to :item + + def current_price + discount_price || price + end end diff --git a/app/views/items/sources.html.haml b/app/views/items/sources.html.haml index 296c28d0..d0bab906 100644 --- a/app/views/items/sources.html.haml +++ b/app/views/items/sources.html.haml @@ -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"