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

コース毎の参考書籍一覧ページを非Vue化した #8158

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
11 changes: 11 additions & 0 deletions app/controllers/courses/books_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,16 @@
class Courses::BooksController < ApplicationController
def index
@course = Course.find(params[:course_id])
@books = Book.with_attached_cover
.eager_load(:practices_books, practices: { categories: :courses_categories })
.where(courses_categories: { course_id: @course.id })
.where(must_read_status)
.order(updated_at: :desc, id: :desc)
end

private

def must_read_status
params[:status] == 'mustread' ? { practices_books: { must_read: true } } : {}
end
end
101 changes: 0 additions & 101 deletions app/javascript/components/course-books.vue

This file was deleted.

2 changes: 0 additions & 2 deletions app/javascript/packs/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ import QuestionAnswers from '../components/question-answers.vue'
import SadReports from '../components/sad_reports.vue'
import UserProducts from '../components/user-products.vue'
import ActionCompletedButton from '../components/action-completed-button.vue'
import CourseBooks from '../components/course-books.vue'

import '../stylesheets/application'

Expand All @@ -86,7 +85,6 @@ mounter.addComponent(QuestionAnswers)
mounter.addComponent(SadReports)
mounter.addComponent(UserProducts)
mounter.addComponent(ActionCompletedButton)
mounter.addComponent(CourseBooks)
mounter.mount()

// Support component names relative to this directory:
Expand Down
54 changes: 53 additions & 1 deletion app/views/courses/books/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,56 @@ header.page-header
= link_to '全て', course_books_path, class: "pill-nav__item-link #{params[:status] == 'mustread' ? '' : 'is-active'}"
li.pill-nav__item
= link_to '必読', course_books_path(status: 'mustread'), class: "pill-nav__item-link #{params[:status] == 'mustread' ? 'is-active' : ''}"
div(data-vue="CourseBooks" data-vue-is-admin:boolean="#{current_user.admin?}" data-vue-is-mentor:boolean="#{current_user.mentor?}" data-vue-course:json="#{@course.to_json}")
.page-body
.page-content.is-books
.container
.books
- if @books.count.positive?
.books__items
.row
- @books.each do |book|
.col-xxxl-2.col-xxl-3.col-xl-4.col-lg-4.col-md-6.col-xs-12
.card-books-item.a-card
.card-books-item__body
.card-books-item__inner
.card-books-item__start
= link_to book.page_url, class: 'card-books-item__cover-container', target: '_blank', rel: 'noopener'
= image_tag(book.cover_url, alt: book.title, class: 'card-books-item__image')
.card-books-item__end
.card-books-item__rows
.card-books-item__row
h2.card-books-item__title
- if book.must_read_for_any_practices?
span.a-badge.is-danger.is-sm
| 必読
= link_to book.page_url, class: 'card-books-item__title-link', target: '_blank', rel: 'noopener'
span.card-books-item__title-label
| #{book.title}
.card-books-item__row
p.card-books-item__price
| #{book.price.to_s(:delimited)}円(税込)
- if book.description.present?
.card-books-item__row
.card-books-item__description
.a-short-text
p
= safe_join(book.description.split(/\n/), tag.br)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pを使用していてクラス名も特にないので、改行せずにそのまま文字列として渡してしまってもいいように思いますが、好みの問題かもしれないので判断はお任せします🙌

p #{safe_join(book.description.split(/\n/), tag.br)}

Copy link
Contributor Author

@ai-24 ai-24 Nov 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

こちら私も改行なしで書こうか迷ったのですが、今後クラスやIDをつけたくなった時に、改行してある方がdiffが減ると考えたのと、他にもpだけで書かれているところを複数見かけたので改行した経緯がありました。(クラスやIDをつける可能性は低いかもしれませんが、、、)
なので特にチームでこの場合は改行しないなどのルールがなく、特に問題なければこのままにしておこうかと思います🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simple_formatなどが使えるかも?です〜

.card-books-item__practices
.tag-links
ul.tag-links__items
- book.practices.each do |practice|
li.tag-links__item
= link_to practice.title, practice_path(practice), class: 'tag-links__item-link'
hr.a-border-tint
- if current_user.admin_or_mentor?
footer.card-footer.is-only-mentor
.card-main-actions
ul.card-main-actions__items
li.card-main-actions__item
= link_to '編集', edit_book_path(book), class: 'card-main-actions__action a-button is-sm is-secondary is-block'
- elsif @books.count.zero?
.o-empty-message
.o-empty-message__icon
i.fa-regular.fa-sad-tear
p.o-empty-message__text
| 登録されている本はありません