Skip to content

Commit e8b5773

Browse files
Merge pull request #36 from sinProject-Inc/35-show-action-counts
close #35
2 parents 09c8e64 + c5d995e commit e8b5773

2 files changed

Lines changed: 31 additions & 4 deletions

File tree

src/routes/home/+page.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const load: PageServerLoad = async ({ locals }) => {
1111
const tweets = await client.tweets.usersIdTimeline(locals.user.twitter_id, {
1212
// max_results: 30,
1313
expansions: ['author_id', 'referenced_tweets.id', 'referenced_tweets.id.author_id'],
14-
'tweet.fields': ['created_at'],
14+
'tweet.fields': ['created_at', 'public_metrics'],
1515
'user.fields': ['profile_image_url'],
1616
// 'tweet.fields': ['author_id'],
1717
// 'tweet.fields': ['created_at', 'entities', 'public_metrics'],

src/routes/home/+page.svelte

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,33 @@
9595
return target_tweet.text ?? ''
9696
}
9797
98+
function get_retweet_count(tweet: components['schemas']['Tweet']): string {
99+
const target_tweet = get_target_tweet(tweet)
100+
101+
const count = target_tweet.public_metrics?.retweet_count ?? 0
102+
const count_text = count > 0 ? count.toLocaleString('ja-JP') : ''
103+
104+
return count_text
105+
}
106+
107+
function get_reply_count(tweet: components['schemas']['Tweet']): string {
108+
const target_tweet = get_target_tweet(tweet)
109+
110+
const count = target_tweet.public_metrics?.reply_count ?? 0
111+
const count_text = count > 0 ? count.toLocaleString('ja-JP') : ''
112+
113+
return count_text
114+
}
115+
116+
function get_like_count(tweet: components['schemas']['Tweet']): string {
117+
const target_tweet = get_target_tweet(tweet)
118+
119+
const count = target_tweet.public_metrics?.like_count ?? 0
120+
const count_text = count > 0 ? count.toLocaleString('ja-JP') : ''
121+
122+
return count_text
123+
}
124+
98125
// console.log(tweets)
99126
</script>
100127

@@ -135,21 +162,21 @@
135162
<div class="tap_area" />
136163
<Reply />
137164
</div>
138-
<div class="icon_text overflow_ellipsis">1,234</div>
165+
<div class="icon_text overflow_ellipsis">{get_reply_count(tweet)}</div>
139166
</div>
140167
<div class="action">
141168
<div class="icon">
142169
<div class="tap_area" />
143170
<Retweet />
144171
</div>
145-
<div class="icon_text overflow_ellipsis">2,345</div>
172+
<div class="icon_text overflow_ellipsis">{get_retweet_count(tweet)}</div>
146173
</div>
147174
<div class="action">
148175
<div class="icon">
149176
<div class="tap_area" />
150177
<Like />
151178
</div>
152-
<div class="icon_text overflow_ellipsis">3,456</div>
179+
<div class="icon_text overflow_ellipsis">{get_like_count(tweet)}</div>
153180
</div>
154181
</div>
155182
</div>

0 commit comments

Comments
 (0)