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

Feature/refactor search results no vue #8125

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
12 changes: 11 additions & 1 deletion app/controllers/searchables_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# frozen_string_literal: true

require 'net/http'
require 'uri'
require 'json'

class SearchablesController < ApplicationController
def index; end
def index
@per = 50
@word = params[:word]
@page_number = params[:page].present? ? params[:page].to_i : 1
request_params = params.permit(:document_type, :word, :page).to_h.to_query
@url = "/api/searchables.json?#{request_params}"
end
end
45 changes: 42 additions & 3 deletions app/views/searchables/index.html.slim
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
- title "'#{params[:word]}'の検索結果"
- set_meta_tags description: "'#{params[:word]}'の検索結果一覧ページです。"
- title "'#{@word}'の検索結果"
- set_meta_tags description: "'#{@word}'の検索結果一覧ページです。"

javascript:
document.addEventListener('DOMContentLoaded', () => {
const url = "#{@url}";
fetch(url)
.then(response => response.json())
.then(data => {
console.log(data);
})
.catch(error => {
console.error('Error:', error);
});
});


header.page-header
.container
Expand All @@ -8,4 +22,29 @@ header.page-header
h2.page-header__title
= title
hr.a-border
= react_component('Searchables', word: params[:word].to_s)
.page-body
- if @error
div
| failed to load
- elsif @data.nil?
.container.is-md
= react_component('LoadingListPlaceholder')
- elsif @data.empty?
.container
.o-empty-message
.o-empty-message__icon
i.fa-regular.fa-sad-tear
p.o-empty-message__text
| #{@word}に一致する情報は見つかりませんでした。
- elsif @data.present?
.container.is-md
- if @data['total_pages'] > 1
nav.pagination
= react_component('Pagination', { sum: @data['total_pages'] * @per, per: @per, neighbours: 2, page: @page_number, setPage: setPage })
.card-list.a-card
- @data['searchables'].each do |searchable|
= render partial: 'searchable', locals: { searchable: searchable, word: @word }
- if @data['total_pages'] > 1
nav.pagination
= react_component('Pagination', { sum: @data['total_pages'] * @per, per: @per, neighbours: 2, page: @page_number, setPage: setPage })
= react_component('Searchables', word: @word.to_s)