-
Notifications
You must be signed in to change notification settings - Fork 0
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
Gifts index #10
Gifts index #10
Conversation
.rubocop.yml
Outdated
@@ -7,6 +7,7 @@ AllCops: | |||
- "node_modules/**/*" | |||
- "db/schema.rb" | |||
- "vendor/bundle/**/*" | |||
- "db/migrate/20240621174351_create_active_storage_tables.active_storage.rb" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you are going to ignore it, ignore all of the migrations folder
app/controllers/gifts_controller.rb
Outdated
before_action :classes_filter, :load_filters_and_categories, only: [:index] | ||
def index |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a line break between before actions and methods
app/models/gift.rb
Outdated
scope :get_gifts_from_categories, lambda { |categories, order| | ||
with_attached_image.includes(:supplier) | ||
.joins(:gift_categorizations) | ||
.where(gift_categorizations: { category_id: categories }) | ||
.order(order).distinct | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a weird scope for the following reasons:
- The name should be something like
with_categories
, so that we can read it likeGift.with_categories(ids)
- It does too many things: it should only do what the name says, join it with categories and filter by category id. Let's remove the includes and the
with_attached_image
scope. Remember that you can chain scopes, so we can do
Gift.with_categories(ids).with_attached_image.includes(:supplier).order(order).distinct
app/controllers/gifts_controller.rb
Outdated
selected_categories | ||
end | ||
query = Gift.get_gifts_from_categories(query_categories, selected_order) | ||
@query_count = query.count |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name is weid. Maybe gifts_count
?
connect(){ | ||
if (this.checkBoxTarget.checked) { | ||
this.labelTarget.classList.add(this.backgroundClass) | ||
this.labelTarget.classList.add(this.textClass) | ||
} | ||
} | ||
check() { | ||
if (this.checkBoxTarget.checked) { | ||
this.labelTarget.classList.add(this.backgroundClass) | ||
this.labelTarget.classList.add(this.textClass) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add some space in between methods
static targets = [ "checkBox", "label" ] | ||
static classes = [ "background", 'text' ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use single qoutes for strings: https://github.com/airbnb/javascript?tab=readme-ov-file#strings--quotes
|
||
// Connects to data-controller="style-labels" | ||
export default class extends Controller { | ||
static targets = [ "checkBox", "label" ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove spaces in brackets: https://github.com/airbnb/javascript?tab=readme-ov-file#whitespace--in-brackets
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
completed gifts index page