File tree Expand file tree Collapse file tree 7 files changed +65
-36
lines changed Expand file tree Collapse file tree 7 files changed +65
-36
lines changed Original file line number Diff line number Diff line change 50
50
"typescript" : " ^5.8.3" ,
51
51
"typescript-svelte-plugin" : " ^0.3.47" ,
52
52
"unocss" : " ^66.1.3" ,
53
+ "valibot" : " ^1.1.0" ,
53
54
"vite" : " npm:rolldown-vite@latest" ,
54
55
"vite-plugin-favicons" : " ^0.1.7"
55
56
},
Original file line number Diff line number Diff line change
1
+ <script lang =' ts' >
2
+ import { Tweet as Sveltweet } from ' sveltweet' ;
3
+ import { getTweet } from ' ./getTweet.remote' ;
4
+
5
+ type Props = Parameters <typeof getTweet >[0 ];
6
+
7
+ const { id }: Props = $props ();
8
+ </script >
9
+
10
+ <svelte:boundary >
11
+ {#snippet pending ()} loading{/ snippet }
12
+ <!-- eslint-disable-next-line antfu/no-top-level-await -->
13
+ <Sveltweet tweet ={await getTweet ({ id })} />
14
+ </svelte:boundary >
Original file line number Diff line number Diff line change
1
+ import { prerender } from '$app/server' ;
2
+ import { retry } from '@std/async' ;
3
+ import { error } from '@sveltejs/kit' ;
4
+ import * as sveltweet from 'sveltweet/api' ;
5
+ import * as v from 'valibot' ;
6
+
7
+ const getTweetPropsSchema = v . object ( {
8
+ id : v . string ( ) ,
9
+ } ) ;
10
+
11
+ /**
12
+ * tweet を取得するRemote function
13
+ * https://svelte.dev/docs/kit/remote-functions#form
14
+ */
15
+ export const getTweet = prerender ( getTweetPropsSchema , async ( { id } ) => {
16
+ const tweet = await retry ( async ( ) => {
17
+ const _tweet = await sveltweet . getTweet ( id ) ;
18
+
19
+ if ( _tweet == null ) {
20
+ throw new Error ( `Retry: Tweet not found: ${ id } ` ) ;
21
+ }
22
+ return _tweet ;
23
+ } ) ;
24
+ if ( tweet == null ) {
25
+ error ( 404 , `Tweet not found: ${ id } ` ) ;
26
+ }
27
+ return tweet ;
28
+ } ) ;
Original file line number Diff line number Diff line change
1
+ import Tweet from './Tweet.svelte' ;
2
+
3
+ export { Tweet } ;
Original file line number Diff line number Diff line change 1
1
<script lang =' ts' >
2
2
import { Heading } from ' $/lib/Heading' ;
3
- import { Tweet } from ' sveltweet' ;
4
- import { getTweets } from ' ./tweet.remote' ;
5
-
6
- const tweets = getTweets ();
3
+ import { LISTENERS_TWEET_IDS } from ' $/lib/links' ;
4
+ import { Tweet } from ' $/lib/Tweet' ;
7
5
</script >
8
6
9
7
<section >
10
8
<Heading title =' リスナーの声' />
11
9
<svelte:boundary >
12
10
<div data-theme =' dark' >
13
- {#each tweets . current as tweet ( tweet . id_str )}
14
- <Tweet {tweet } />
11
+ {#each LISTENERS_TWEET_IDS as id ( id )}
12
+ <Tweet {id } />
15
13
{/each }
16
14
</div >
17
15
</svelte:boundary >
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments