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

今日飲む酒をキメるガチャ的なもの #851

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

momocus
Copy link
Owner

@momocus momocus commented Jan 18, 2025

Fixes #850

酒一覧ページ酒ガチャボタンを追加しました

default.mp4

Copy link

github-actions bot commented Jan 18, 2025

📦 esbuild Bundle Analysis for sakazuki

This analysis was generated by esbuild-bundle-analyzer. 🤖

Meta File Out File Size (raw) Note
meta.json app/assets/builds/application.js 1.01 MB ⚠️ +1.14 KB (+0.1%)
Largest paths These visualization shows top 20 largest paths in the bundle.

Meta file: meta.json, Out file: app/assets/builds/application.js

Path Size
node_modules/chart.js/dist ${{\color{Goldenrod}{ ██████▊ }}}$ 27.3%, 274.56 KB
app/javascript/completion ${{\color{Goldenrod}{ ████▎ }}}$ 17.2%, 173.25 KB
node_modules/@hotwired/turbo ${{\color{Goldenrod}{ ███▎ }}}$ 13.1%, 131.96 KB
node_modules/bootstrap/dist ${{\color{Goldenrod}{ ███ }}}$ 12.4%, 124.43 KB
node_modules/simplelightbox/dist ${{\color{Goldenrod}{ ██▏ }}}$ 8.7%, 87.43 KB
node_modules/@hotwired/stimulus ${{\color{Goldenrod}{ ██ }}}$ 8.4%, 84.29 KB
node_modules/@popperjs/core ${{\color{Goldenrod}{ █▍ }}}$ 5.5%, 55.65 KB
node_modules/@rails/actioncable ${{\color{Goldenrod}{ ▍ }}}$ 1.9%, 19.51 KB
node_modules/rater-js/index.js ${{\color{Goldenrod}{ ▍ }}}$ 1.6%, 16.36 KB
node_modules/@kurkle/color ${{\color{Goldenrod}{ ▎ }}}$ 1.3%, 13.37 KB
app/javascript/controllers ${{\color{Goldenrod}{ ▎ }}}$ 1.0%, 10.11 KB
app/javascript/taste_graph ${{\color{Goldenrod}{ ▏ }}}$ 0.7%, 7.53 KB
node_modules/@hotwired/turbo-rails ${{\color{Goldenrod}{ }}}$ 0.4%, 3.80 KB
node_modules/ts-deepmerge/esm ${{\color{Goldenrod}{ }}}$ 0.2%, 1.69 KB
node_modules/just-zip-it/index.mjs ${{\color{Goldenrod}{ }}}$ 0.1%, 785 B
node_modules/chart.js/helpers ${{\color{Goldenrod}{ }}}$ 0.0%, 0 B
app/javascript/application.js ${{\color{Goldenrod}{ }}}$ 0.0%, 0 B
Details

Next to the size is how much the size has increased or decreased compared with the base branch of this PR.

  • ‼️: Size increased by 20% or more. Special attention should be given to this.
  • ⚠️: Size increased in acceptable range (lower than 20%).
  • ✅: No change or even downsized.
  • 🗑️: The out file is deleted: not found in base branch.
  • 🆕: The out file is newly found: will be added to base branch.

@momocus momocus marked this pull request as draft January 18, 2025 11:25
Fixes #850

Add functionality to randomly select a drink from the available stock when clicking the sake cup icon in the top left corner.

* Modify `app/views/layouts/_header.html.erb` to add a data-controller attribute to the sake cup icon link.
* Modify `app/controllers/sakes_controller.rb` to add a `random` action that selects a random drink from the available stock and redirects to its show page. Add a private method to fetch a random sake from the available stock.
* Modify `config/routes.rb` to add a route for the `random` action in the `SakesController`.
* Add `app/javascript/controllers/random_drink_controller.ts` to create a Stimulus controller that handles the click event on the sake cup icon and makes an AJAX request to the `random` action.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/momocus/sakazuki/issues/850?shareId=XXXX-XXXX-XXXX-XXXX).
@momocus momocus force-pushed the add-random-drink-button branch from 4fe2220 to da21cdf Compare January 19, 2025 04:38
@momocus
Copy link
Owner Author

momocus commented Jan 19, 2025

/fix

@momocus momocus changed the title Add random drink button 酒ガチャ Jan 19, 2025
@momocus momocus changed the title 酒ガチャ 今日飲む酒をキメるガチャ的なもの Jan 19, 2025
@momocus momocus marked this pull request as ready for review January 19, 2025 05:48
@@ -0,0 +1,49 @@
import { Controller } from "@hotwired/stimulus"

type DrinkData = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

型で名前をつけてえらい!

@@ -79,3 +79,6 @@ ja:
price_is_per_go: 一合当たりのお値段となり〼
menu_one_drink:
new_arrival: 新着
shuffle:
title: 日本酒ガチャ
Copy link
Collaborator

Choose a reason for hiding this comment

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

ガチャは悪しき文明!!
名前がたいへん愉快でよい!

Copy link
Collaborator

@yonta yonta left a comment

Choose a reason for hiding this comment

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

がぞーうーほーしーいー

@@ -117,5 +117,12 @@
expect { delete sake_path(id) }.to change(Sake, :count).by(-1)
end
end

Copy link
Collaborator

Choose a reason for hiding this comment

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

JSONの中身に関するテストどうしようね。
今までJSON APIなかったから目をつむってきたけど…

@@ -30,3 +30,6 @@ application.register("show-taste-graph", ShowTasteGraphController)

import SimpleLightboxController from "./simple_lightbox_controller"
application.register("simple-lightbox", SimpleLightboxController)

Copy link
Collaborator

Choose a reason for hiding this comment

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

これはrails generate stimulus CONTROLER_NAMEでアルファベットオーダーで挿入しているので揃えてください。

name: string
}

export default class extends Controller {
Copy link
Collaborator

Choose a reason for hiding this comment

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

無名クラスではなく名前をつけておいてね。
他のTSファイルを参照。

declare readonly resultTarget: HTMLElement

connect() {
this.shuffleTarget.addEventListener("click", () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

clickイベントへの接続はdata-actionで接続できるはず。

console.error(error)
})
})
this.buttonTarget.addEventListener("click", () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

同上

}

displayRandomDrink(data: DrinkData) {
this.resultTarget.innerHTML = `
Copy link
Collaborator

Choose a reason for hiding this comment

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

テンプレートリテラルの改行は改行のまま出力される。
この結果の文字列は"\n<h1>...</h1>\n"と先頭・末尾にいらない改行が入るね。

@@ -0,0 +1,25 @@
<div data-controller="random-drink" class="d-inline">
Copy link
Collaborator

Choose a reason for hiding this comment

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

TSのファイル名がrandom_drink_controller.tsだし、これもパーシャルビューの名前もshuffleよりもrandome drinkでそろえるほうが分かりやすいと思う。

@@ -5,7 +5,7 @@
<%= link_to(
sanitize("#{image_tag('choko.svg', class: 'sakazuki-header-logo')}SAKAZUKI", tag: %w[img]),
root_path,
{ class: "navbar-brand d-flex align-items-center" },
Copy link
Collaborator

Choose a reason for hiding this comment

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

RandomDrinkコントローラがロゴ・タイトルに結び付けられている。
しかしこのコントローラが操作するのはロゴ・タイトルではない。

<% else %>
<%# 通常タイトル %>
<% header = t(".header") %>
<% include_empty = include_empty?(params[:q]) %>
<% h1 = t(".h1_with_stock", stock: stock(include_empty)) %>
<%= title(header, h1) %>
<%= render(partial: "shuffle") %>
Copy link
Collaborator

Choose a reason for hiding this comment

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

このifは検索されているor検索されていないの意味。
その中にガチャボタンを出すかどうかが書いてある。
検索している・しない、にガチャを表示するかどうかは関係がない。

例えば、検索はしていないが、空き瓶込みの表示でもガチャボタンが出る。
でもガチャは空き瓶を対象にしていない。

ガチャは検索や空き瓶表示をサポートしないので、表示に合うときだけガチャボタンをだすべきでは。

<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div data-random-drink-target="result" data-bs-dismiss="modal"></div>
Copy link
Collaborator

Choose a reason for hiding this comment

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

ここのbodyは文字列要素なのでdivブロックではなくpインライン要素

@yonta
Copy link
Collaborator

yonta commented Jan 20, 2025

酒ガチャという名前が大変気に入ったので、モジュール名やパーシャルビュー名もSakeGachaにしようぜ!!

@yonta
Copy link
Collaborator

yonta commented Jan 22, 2025

@momocus
やや隠し機能的に遊びの意味が含まれたアイコンもいいかなぁと。
bootstrap iconsを色々見てみた

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

今日飲む酒をキメるガチャ的なものが欲しい
2 participants