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

Marketplace: Improve the UI #857

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,10 @@ GEM
actionpack (>= 3.1, < 7.1)
railties (>= 3.1, < 7.1)
ruby2_keywords (0.0.5)
sentry-rails (5.4.2)
sentry-rails (5.5.0)
railties (>= 5.0)
sentry-ruby (~> 5.4.2)
sentry-ruby (5.4.2)
sentry-ruby (~> 5.5.0)
sentry-ruby (5.5.0)
concurrent-ruby (~> 1.0, >= 1.0.2)
shoulda-matchers (5.2.0)
activesupport (>= 5.2.0)
Expand Down Expand Up @@ -349,7 +349,7 @@ GEM
websocket-driver (0.7.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
zeitwerk (2.6.0)
zeitwerk (2.6.1)

PLATFORMS
ruby
Expand Down
2 changes: 1 addition & 1 deletion app/furniture/marketplace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Marketplace

def self.append_routes(router)
router.resource :marketplace, only: [] do
router.resources :products, only: %i[create index], module: 'marketplace'
router.resources :products, only: %i[new create index], module: 'marketplace'
end
end

Expand Down
13 changes: 1 addition & 12 deletions app/furniture/marketplace/_marketplace.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1 @@
<h2>Marketplace</h2>

<div>
<h3>Products</h3>
<%= render marketplace.products %>
</div>
<%= form_with model: [marketplace.space, marketplace.room, marketplace.products.new] do |f| %>
<%= render "text_field", { attribute: :name, form: f} %>
<%= render "text_area", { attribute: :description, form: f} %>
<%= render "number_field", { attribute: :price_cents, form: f} %>
<%= f.submit %>
<% end %>
<%= render partial: "marketplace/marketplace/marketplace", object: marketplace %>
26 changes: 26 additions & 0 deletions app/furniture/marketplace/marketplace/_marketplace.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<%= turbo_frame_tag marketplace do %>
<div class="-mx-4 mt-8 overflow-hidden shadow ring-1 ring-black ring-opacity-5 sm:-mx-6 md:mx-0 md:rounded-lg">
<table class="min-w-full divide-y divide-gray-300">
<thead class="bg-gray-50">
<tr>
<th scope="col" class="py-3.5 pl-4 pr-3 text-left text-sm font-semibold text-gray-900 sm:pl-6">
<%= Marketplace::Product.human_attribute_name(:name) %>
</th>
<th scope="col" class="hidden px-3 py-3.5 text-left text-sm font-semibold text-gray-900 sm:table-cell">
<%= Marketplace::Product.human_attribute_name(:description) %>
</th>
<th scope="col" class="hidden px-3 py-3.5 text-left text-sm font-semibold text-gray-900 lg:table-cell">
<%= Marketplace::Product.human_attribute_name(:price) %>
</th>
<th scope="col" class="relative py-3.5 pl-3 pr-4 sm:pr-6 text-right">
<span class="sr-only">Actions</span>
<%= render "buttons/new", title: t('marketplace.products.new'), href: [:new, marketplace.space, marketplace.room, marketplace, :product] %>
</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-200 bg-white">
<%= render marketplace.products %>
</tbody>
</table>
</div>
<%- end %>
5 changes: 5 additions & 0 deletions app/furniture/marketplace/product.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# frozen_string_literal: true

class Marketplace
class Product < ApplicationRecord
self.table_name = 'marketplace_products'
attribute :name, :string
attribute :description, :string
monetize :price_cents
belongs_to :space
end
end
23 changes: 18 additions & 5 deletions app/furniture/marketplace/products/_product.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
<h4><%= product.name %></h4>

<%= product.description %>

<hr>
<tr>
<td class="w-full max-w-0 py-4 pl-4 pr-3 text-sm font-medium text-gray-900 sm:w-auto sm:max-w-none sm:pl-6">
<%= product.name %>
<dl class="font-normal lg:hidden">
<dt class="sr-only"><%= product.class.human_attribute_name(:description) %></dt>
<dd class="mt-1 truncate text-gray-700"><%= product.description %></dd>
</dl>
</td>
<td class="hidden px-3 py-4 text-sm text-gray-500 lg:table-cell">
<%= product.description %>
</td>
<td class="hidden px-3 py-4 text-sm text-gray-500 sm:table-cell">
<%= humanized_money_with_symbol(product.price) %>
</td>
<td class="py-4 pl-3 pr-4 text-right text-sm font-medium sm:pr-6">
<%= render "buttons/new", label: "🛒", title: t('marketplace.products.new'), href: "#" %>
</td>
</tr>
1 change: 1 addition & 0 deletions app/furniture/marketplace/products/create.turbo_stream.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= turbo_stream.replace(marketplace, marketplace) %>
8 changes: 8 additions & 0 deletions app/furniture/marketplace/products/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<%= turbo_frame_tag marketplace do %>
<%= form_with model: [marketplace.space, marketplace.room, marketplace.products.new] do |f| %>
<%= render "text_field", { attribute: :name, form: f} %>
<%= render "text_area", { attribute: :description, form: f} %>
<%= render "number_field", { attribute: :price_cents, form: f} %>
<%= f.submit %>
<% end %>
<%- end %>
11 changes: 9 additions & 2 deletions app/furniture/marketplace/products_controller.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
class Marketplace
class ProductsController < FurnitureController
def new

end

def create
product = marketplace.products.new(product_params)
product.save!

render product
respond_to do |format|
format.turbo_stream
format.html { redirect_to [space, room] }
end
end

def marketplace
helper_method def marketplace
Marketplace.find_by(room: room)
end

Expand Down
7 changes: 6 additions & 1 deletion app/furniture/spotlight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

class Spotlight
include Placeable
delegate :alt_text,:alt_text=, to: :image

def self.deprecated_append_routes(router)
router.scope module: 'spotlight' do
Expand All @@ -15,6 +16,10 @@ def image
Image.find_or_initialize_by(location: placement, space: placement.space)
end

def alt_text=text
image.update(alt_text:text)
end

def file=file
image.file.attach(file)
end
Expand All @@ -26,6 +31,6 @@ def in_room_template
end

def attribute_names
%w[file]
%w[file alt_text]
end
end
1 change: 1 addition & 0 deletions app/furniture/spotlight/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<%= form.fields_for(:furniture) do |furniture_fields| %>
<%= render "file_field", form: furniture_fields, attribute: :file %>
<%= render "text_field", form: furniture_fields, attribute: :alt_text %>
<%- end %>
2 changes: 1 addition & 1 deletion app/furniture/spotlight/_in_room.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

<%- if furniture.image.file.present? %>
<%= image_tag furniture.image.file %>
<%= image_tag furniture.image.file, alt: furniture.alt_text %>
<%- end %>
7 changes: 7 additions & 0 deletions app/furniture/spotlight/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,12 @@
class Spotlight
class Image < Item
has_one_attached :file
def alt_text=text
data["alt_text"]=text
end

def alt_text
data["alt_text"]
end
end
end
6 changes: 6 additions & 0 deletions app/views/buttons/_new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<%- label = local_assigns.fetch(:label, t('icons.new')) %>
<%- title = local_assigns.fetch(:title) %>
<%- href = local_assigns.fetch(:href) %>

<%= link_to label, href, title: title,
class: 'no-underline bg-transparent hover:bg-primary-100 button' %>
2 changes: 1 addition & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
config.logger = ActiveSupport::Logger.new(STDOUT)

# Annotate rendered view with file names.
# config.action_view.annotate_rendered_view_with_filenames = true
config.action_view.annotate_rendered_view_with_filenames = true

# Uncomment if you wish to allow Action Cable access from any origin.
# config.action_cable.disable_request_forgery_protection = true
Expand Down
3 changes: 2 additions & 1 deletion config/locales/icon/en.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
en:
icons:
edit: '⚙️'
remove: '🗑️'
remove: '🗑️'
new: '➕'
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"@webpack-cli/serve": "^1.7.0",
"autoprefixer": "^10.4.12",
"event-target-shim": "^6.0.2",
"postcss": "^8.4.16",
"postcss": "^8.4.17",
"postcss-cli": "^10.0.0",
"postcss-flexbugs-fixes": "^5.0.2",
"postcss-import": "^15.0.0",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3433,10 +3433,10 @@ postcss-value-parser@^4.0.0, postcss-value-parser@^4.2.0:
resolved "https://registry.yarnpkg.com/postcss-value-parser/-/postcss-value-parser-4.2.0.tgz#723c09920836ba6d3e5af019f92bc0971c02e514"
integrity sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ==

postcss@^8.4.14, postcss@^8.4.16:
version "8.4.16"
resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.4.16.tgz#33a1d675fac39941f5f445db0de4db2b6e01d43c"
integrity sha512-ipHE1XBvKzm5xI7hiHCZJCSugxvsdq2mPnsq5+UF+VHCjiBvtDrlxJfMBToWaP9D5XlgNmcFGqoHmUn0EYEaRQ==
postcss@^8.4.14, postcss@^8.4.17:
version "8.4.17"
resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.4.17.tgz#f87863ec7cd353f81f7ab2dec5d67d861bbb1be5"
integrity sha512-UNxNOLQydcOFi41yHNMcKRZ39NeXlr8AxGuZJsdub8vIb12fHzcq37DTU/QtbI6WLxNg2gF9Z+8qtRwTj1UI1Q==
dependencies:
nanoid "^3.3.4"
picocolors "^1.0.0"
Expand Down