Skip to content

Commit

Permalink
Add: Add quick search
Browse files Browse the repository at this point in the history
  • Loading branch information
sevenc-nanashi committed Apr 5, 2024
1 parent 2eac8e6 commit c6f28b6
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 60 deletions.
59 changes: 50 additions & 9 deletions backend/app/controllers/sonolus/levels_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def info
end

def list
params.permit(:page, *(self.class.search_options.map { |o| o[:query] }))
params.permit(:page, :type, :keywords, *(self.class.search_options.map { |o| o[:query] }))

charts =
Chart
Expand Down Expand Up @@ -141,6 +141,10 @@ def list
charts =
charts.where("LOWER(title) LIKE ?", "%#{params[:q_title].downcase}%")
end
if params[:type] == "quick" && params[:keywords].present?
charts =
charts.where("LOWER(title) LIKE ?", "%#{params[:keywords].downcase}%")
end
if params[:q_composer].present?
charts =
charts.where(
Expand Down Expand Up @@ -175,9 +179,13 @@ def list
cover: "error"
)
],
search: {
options: self.class.search_options
},
searches: [
{
type: "advanced",
title: "#ADVANCED",
options: self.class.search_options
}
],
pageCount: 1
}
return
Expand Down Expand Up @@ -226,9 +234,13 @@ def list

render json: {
items: charts.map(&:to_sonolus),
search: {
options: self.class.search_options
},
searches: [
{
type: "advanced",
title: "#ADVANCED",
options: self.class.search_options
}
],
pageCount: page_count
}
end
Expand Down Expand Up @@ -289,8 +301,37 @@ def show
user_faved = chart.likes.exists?(user_id: current_user&.id)
render json: {
item: chart.to_sonolus,
sections: [
].flatten.compact,
sections:
[
{
title: I18n.t("sonolus.sections.actions"),
items: [
(
if user_faved
dummy_level(
"like.button.to_off",
"like-off-#{chart.name}",
cover: "like_on"
)
else
dummy_level(
"like.button.to_on",
"like-on-#{chart.name}",
cover: "like_off"
)
end
)
]
},
{
title: I18n.t("sonolus.sections.vary_from"),
items: [chart.variant_of&.to_sonolus]
},
{
title: I18n.t("sonolus.sections.variants"),
items: chart.variants.map(&:to_sonolus)
}
].filter { |section| section[:items].any? },
description: chart.sonolus_description
}
else
Expand Down
29 changes: 4 additions & 25 deletions backend/config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
en:
auth:
title: "Chart Cyanvas: Login Server"
code_search:
option:
name: "Code"
placeholder: "Please enter 8 digits code"
test:
title: "Chart Cyanvas: Test Server"
levels:
Expand Down Expand Up @@ -40,25 +34,6 @@ en:
title: "Not liked."
description: "You have not liked this chart. Please tap the upper right button to go back."

auth:
welcome:
title: "Welcome to Chart Cyanvas!"
description: "Please tap the [ Search ] button to enter the code."
guide:
title: "Please tap the [ Search ] button below to enter the code."
description: "Do not use code by other people!"
confirm:
title: "Login with [ %{code} ]?"
description: "Do not use code by other people!"
invalid:
title: "Invalid code!"
description: "The code should be 8 digits."
expired:
title: "Unknown code!"
description: "The code has expired or you have typo'd. Please try again."
success:
title: "Login successful!"
description: "Please go back to your browser."
test:
welcome:
title: "Welcome to Chart Cyanvas!"
Expand All @@ -74,6 +49,10 @@ en:
Likes: %{likes} / Tag(s): %{tags}
%{description}
sections:
actions: "Actions"
variant_of: "Vary from"
variants: "Variants"
search:
title: "Title"
title_placeholder: "Please enter the title..."
Expand Down
33 changes: 7 additions & 26 deletions backend/config/locales/ja.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
ja:
auth:
title: "Chart Cyanvas:ログインサーバー"
code_search:
option:
name: "コード"
placeholder: "8桁のコードを入力して下さい。"
test:
title: "Chart Cyanvas:テストサーバー"
levels:
Expand Down Expand Up @@ -40,38 +34,25 @@ ja:
title: "この譜面は高評価されていません。"
description: "右上のボタンで前の画面に戻ります。"

auth:
welcome:
title: "Chart Cyanvas ログインサーバーへようこそ!"
description: "下の [ 検索 ] ボタンを押してコードを入力して下さい。"
guide:
title: "下の [ 検索 ] ボタンを押してコードを入力して下さい。"
description: "他人から貰ったコードは使用しないで下さい!"
confirm:
title: "[ %{code} ] でログインしますか?"
description: "他人から貰ったコードは使用しないで下さい!"
invalid:
title: "コードが無効です!"
description: "コードは数字8桁で構成されています。"
expired:
title: "コードが無効です!"
description: "認証コードが見付かりませんでした。数字を間違えていないか確認して下さい。"
success:
title: "ログインしました!"
description: "ブラウザに戻ってください。"

test:
welcome:
title: "Chart Cyanvas テストサーバーへようこそ!"
description: "下の [ もっと ] ボタンを押すと譜面一覧に移動します。"
sonolus:
title: "Chart Cyanvas"
info:
description: "Chart Cyanvas は Sonolus 用の某セカイ創作譜面プラットフォームです。"
logged_in: "%{name}#%{handle} としてログインしています。"
tag_separator: ""
levels:
description: |
高評価:%{likes} / タグ:%{tags}
%{description}
sections:
actions: "操作"
variant_of: "派生元"
variants: "派生譜面"
search:
title: "タイトル"
title_placeholder: "タイトルを入力して下さい..."
Expand Down

0 comments on commit c6f28b6

Please sign in to comment.