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

「2回連続sadのユーザー」のカードをVue化する #5621

Merged
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
13 changes: 13 additions & 0 deletions app/controllers/api/reports/sad_streak_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

class API::Reports::SadStreakController < API::BaseController
def index
ids = User.where(
hibernated_at: nil,
retired_on: nil,
graduated_on: nil,
sad_streak: true
).pluck(:last_sad_report_id)
@reports = Report.joins(:user).where(id: ids).order(reported_on: :desc)
end
end
47 changes: 47 additions & 0 deletions app/javascript/components/sad_reports.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<template lang="pug">
.card-list__items(v-if='reports && reports.length > 0')
report(
v-for='report in reports',
:key='report.id',
:report='report',
:current-user-id='currentUserId',
:display-user-icon='displayUserIcon')
</template>
<script>
import Report from 'components/report.vue'

export default {
name: 'SadReports',
components: {
report: Report
},
props: {
displayUserIcon: {
type: Boolean,
default: true
}
},
data() {
return {
reports: null,
currentUserId: null
}
},
created() {
this.getSadReports()
},
methods: {
async getSadReports() {
const response = await fetch('/api/reports/sad_streak.json', {
method: 'GET',
headers: { 'X-Requested-With': 'XMLHttpRequest' },
credentials: 'same-origin',
redirect: 'manual'
}).catch((error) => console.warn(error))
const json = await response.json().catch((error) => console.warn(error))
this.reports = json.reports
this.currentUserId = json.currentUserId
}
}
}
</script>
2 changes: 2 additions & 0 deletions app/javascript/packs/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import Talks from '../components/talks.vue'
import Footprints from '../components/footprints.vue'
import QuestionPage from '../components/question-page.vue'
import QuestionEdit from '../components/question-edit.vue'
import SadReports from '../components/sad_reports.vue'

const mounter = new VueMounter()
mounter.addComponent(Announcements)
Expand All @@ -99,6 +100,7 @@ mounter.addComponent(Talks)
mounter.addComponent(Footprints)
mounter.addComponent(QuestionPage)
mounter.addComponent(QuestionEdit)
mounter.addComponent(SadReports)
mounter.mount()

// Support component names relative to this directory:
Expand Down
10 changes: 10 additions & 0 deletions app/views/api/reports/sad_streak/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
json.reports @reports do |report|
json.partial! "api/reports/report", report: report
json.partial! "api/reports/checks", checks: report.checks
json.partial! "api/comments/user_icons", comments: report.comments
json.user do
json.partial! "api/users/user", user: report.user
end
end

json.currentUserId current_user.id
66 changes: 0 additions & 66 deletions app/views/reports/_report.html.slim

This file was deleted.

2 changes: 1 addition & 1 deletion app/views/users/_sad_emotion_report.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
= image_tag Report.faces['sad'], id: 'sad', alt: 'sad', class: 'card-header__title-emotion-image'
| のユーザー
.card-list
= render partial: 'reports/report', collection: reports, as: :report
div(data-vue="SadReports")
1 change: 1 addition & 0 deletions config/routes/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
get 'counts', on: :collection
end
resources :recents, only: %i(index)
resources :sad_streak, only: %i(index)
end
resources :watches, only: %i(index)
namespace "watches" do
Expand Down