-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTheTagWrapper.vue
221 lines (219 loc) · 6.07 KB
/
TheTagWrapper.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<template>
<div>
<!-- タブ -->
<the-tab :registered-tags="registeredTags" />
<!-- カレンダー -->
<the-calendar
ref="calendar"
:tweet-dates="tweetDates"
@input-date="fetchDateTweets"
/>
<v-container class="main-content d-flex flex-row-reverse pt-0" row>
<!-- ハッシュタグの情報 -->
<v-col cols="12" md="4" class="px-0">
<v-card flat>
<tag-status
ref="tagStatus"
:registered-tag.sync="registeredTag"
@push-delete="$emit('push-delete')"
@push-update="$emit('push-update', registeredTag)"
@push-cancel="fetchTagData"
@push-tweet="$refs.tweetDialog.open()"
/>
</v-card>
<!-- 広告 -->
<a target="_blank" rel="noopener" href="https://runteq.jp/r/FKSRkiAh">
<v-img
class="mt-3 d-none d-sm-block"
alt="RUNTEQ"
src="/img/runteq/300_50.jpg"
/>
</a>
</v-col>
<!-- ツイートダイアログ -->
<tweet-dialog
ref="tweetDialog"
:tweeted-day-count="registeredTag.tweetedDayCount"
:last-tweeted-at="registeredTag.lastTweetedAt"
:tag-name="registeredTag.tag.name"
@create-tweet="updateTweetsData"
/>
<!-- ツイート -->
<v-col cols="12" md="8" class="px-0 pt-0">
<tweets-view :tweets="tweets" :user="user" />
</v-col>
</v-container>
<!-- ページネーション -->
<div class="text-center">
<v-pagination
v-model="page.currentPage"
:length="page.totalPages"
:total-visible="7"
@input="changePaginationPage"
/>
</div>
</div>
</template>
<script>
import theCalendar from "./TheCalendar"
import tagStatus from "./TagStatus"
import theTab from "./TagsTab"
import tweetsView from "./TagsTweets"
import tweetDialog from "./TheTweetDialog"
export default {
components: {
theCalendar,
tagStatus,
theTab,
tweetsView,
tweetDialog
},
props: {},
data() {
return {
user: {
tweetId: "",
screenName: "",
name: "",
description: "",
privacy: ""
},
page: {
currentPage: 1,
totalPages: 1,
requestUrl: ""
},
registeredTag: {
id: "",
tweetedDayCount: 0,
privacy: "",
remindDay: 0,
firstTweetedAt: "",
lastTweetedAt: "",
tag: {
name: ""
}
},
registeredTags: [],
tweets: [],
tweetDates: []
}
},
computed: {
isMypage() {
return this.$route.path.includes("/mypage/")
},
registeredTagUrl() {
const { tagId } = this.$route.params
return `/api/v1/registered_tags/${tagId}`
},
isOpened() {
return (
this.user.privacy === "公開" && this.registeredTag.privacy !== "非公開"
)
}
},
watch: {
$route() {
this.firstRead()
}
},
created() {
this.firstRead()
},
methods: {
async firstRead() {
this.fetchRegisteredTagsData()
this.fetchUserData()
this.fetchTweetDates()
this.fetchTweetsData()
await this.fetchTagData()
document.title = `#${this.registeredTag.tag.name} - Hashlog`
},
updateTweetsData() {
this.fetchTweetDates()
this.fetchTweetsData()
},
async fetchTagData() {
const registeredTagRes = await this.$axios.get(this.registeredTagUrl)
const { registeredTag } = registeredTagRes.data
this.registeredTag = registeredTag
},
async fetchTweetsData() {
const tweetsRes = await this.$axios.get(
`${this.registeredTagUrl}/tweets?page=1`
)
this.setPaginationData(tweetsRes)
const { tweets } = tweetsRes.data
this.tweets = tweets
},
// タブ用ユーザーの全てのタグ
async fetchRegisteredTagsData() {
if (this.isMypage) {
const registeredTagsRes = await this.$axios.get(
"/api/v1/users/current/registered_tags"
)
const { registeredTags } = registeredTagsRes.data
this.registeredTags = registeredTags
return
}
const { userUuid } = await this.$route.params
const registeredTagsRes = await this.$axios.get(
`/api/v1/users/${userUuid}/registered_tags`
)
const { registeredTags } = registeredTagsRes.data
this.registeredTags = registeredTags
},
// ユーザー
async fetchUserData() {
if (this.isMypage) {
const userRes = await this.$axios.get("/api/v1/users/current")
const { user } = userRes.data
this.user = user
return
}
const { userUuid } = this.$route.params
const userRes = await this.$axios.get(`/api/v1/users/${userUuid}`)
const { user } = userRes.data
this.user = user
},
// カレンダー用日付データ
async fetchTweetDates() {
this.tweetDates = []
const tweetsRes = await this.$axios.get(
`${this.registeredTagUrl}/tweeted_ats`
)
const { tweetedAts } = tweetsRes.data
tweetedAts.forEach(t => this.tweetDates.push(t.substr(0, 10)))
this.date = ""
},
// カレンダーの日付の変更
async fetchDateTweets(date) {
this.page.currentPage = 1
const tweetsRes = await this.$axios.get(
`${this.registeredTagUrl}/tweets?page=1&date=${date}`
)
this.setPaginationData(tweetsRes)
const { tweets } = tweetsRes.data
this.tweets = tweets
},
// ページネーション
setPaginationData(response) {
this.page.totalPages = Number(response.headers["total-pages"])
this.page.requestUrl = response.headers["request-url"]
},
async changePaginationPage(val) {
this.$toTop()
const res = await this.$axios.get(this.paginationUrl(val))
const { tweets } = res.data
this.tweets = tweets
},
paginationUrl(page) {
if (this.$refs.calendar.date) {
return `${this.page.requestUrl}?date=${this.$refs.calendar.date}&page=${page}`
}
return `${this.page.requestUrl}?page=${page}`
}
}
}
</script>