@@ -5,15 +5,16 @@ import {
5
5
createSignal ,
6
6
ErrorBoundary ,
7
7
For ,
8
+ Show ,
8
9
Suspense ,
9
- untrack ,
10
10
} from "solid-js" ;
11
11
import { createStore , SetStoreFunction } from "solid-js/store" ;
12
- import { listPartitions , listPictures } from "../api/api" ;
12
+ import { listPartitions , listPictures , upload } from "../api/api" ;
13
13
import Loading from "../components/Loading" ;
14
14
import Pagination from "../components/Pagination" ;
15
15
import PictureCard from "../components/PictureCard" ;
16
16
import Placeholder from "../components/Placeholder" ;
17
+ import Button from "../components/Button" ;
17
18
18
19
const PartitionSelector = ( props : {
19
20
current : string ;
@@ -24,7 +25,7 @@ const PartitionSelector = (props: {
24
25
} ) => {
25
26
const [ partitions ] = createResource ( listPartitions ) ;
26
27
return (
27
- < div class = "relative pt-4 " >
28
+ < div class = "relative" >
28
29
< Suspense fallback = { < Loading /> } >
29
30
< select
30
31
onChange = { ( event ) => {
@@ -50,6 +51,33 @@ focus:text-gray-700 focus:bg-white focus:border-blue-600 focus:outline-none"
50
51
) ;
51
52
} ;
52
53
54
+ const Uploader = ( props : { partition : string } ) => {
55
+ const [ image , setImage ] = createSignal < File > ( ) ;
56
+ const fetcher = ( file : File ) => upload ( file , props . partition ) ;
57
+
58
+ const [ data ] = createResource ( image , fetcher ) ;
59
+
60
+ return < form class = "flex items-start gap-4" onSubmit = { async ( event ) => {
61
+ event . preventDefault ( ) ;
62
+ const file = event . target [ "image" ] . files [ 0 ] ;
63
+ setImage ( file ) ;
64
+ } } >
65
+ < div class = "flex flex-col items-start gap-4" >
66
+ < input name = "image" type = "file" />
67
+ < Button type = "submit" disabled = { data . loading } > Upload</ Button >
68
+ </ div >
69
+
70
+ < Show when = { data ( ) } >
71
+ < div >
72
+ < h3 > Success!</ h3 >
73
+ < ul >
74
+ < For each = { Array . from ( Object . entries ( data ( ) ) ) } > { ( [ key , value ] ) => < li > { key } : < a href = { value [ "url" ] } > { value [ "url" ] } </ a > </ li > } </ For >
75
+ </ ul >
76
+ </ div >
77
+ </ Show >
78
+ </ form >
79
+ }
80
+
53
81
export default function Main ( ) {
54
82
const navigate = useNavigate ( ) ;
55
83
const param = useParams ( ) ;
@@ -71,8 +99,17 @@ export default function Main() {
71
99
return < Placeholder text = { e . toString ( ) } />
72
100
} } >
73
101
< Suspense fallback = { < Loading /> } >
74
- < section class = "flex justify-end min-h-10" >
75
- < PartitionSelector current = { store . partition } setter = { setStore } />
102
+ < section class = "flex justify-between items-end min-h-10 gap-4 pt-4" >
103
+ < div >
104
+ < ErrorBoundary fallback = { ( e ) => < p > { `${ e } ` } </ p > } >
105
+ < Suspense fallback = { < Loading /> } >
106
+ < Uploader partition = { store . partition } />
107
+ </ Suspense >
108
+ </ ErrorBoundary >
109
+ </ div >
110
+ < div >
111
+ < PartitionSelector current = { store . partition } setter = { setStore } />
112
+ </ div >
76
113
</ section >
77
114
< section class = "mt-4 min-h-96" >
78
115
< div class = "grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-6 " >
0 commit comments