1
1
import type { MetaFunction } from "@remix-run/node" ;
2
+ import { useLoaderData } from "@remix-run/react" ;
3
+ import { useCopyToClipboard } from "@uidotdev/usehooks" ;
4
+ import { desc } from "drizzle-orm" ;
5
+ import { PiClipboardBold , PiPlayBold } from "react-icons/pi" ;
6
+
7
+ import { dborm } from "~/db/connection.server" ;
8
+ import { regex_share } from "~/db/schema" ;
2
9
3
10
export const meta : MetaFunction = ( ) => {
4
11
return [
@@ -7,13 +14,44 @@ export const meta: MetaFunction = () => {
7
14
] ;
8
15
} ;
9
16
17
+ export async function loader ( ) {
18
+
19
+ const theShares = await dborm . select ( ) . from ( regex_share ) . orderBy ( desc ( regex_share . rxs_created_at ) ) . limit ( 100 ) ;
20
+
21
+ return theShares ;
22
+ }
23
+
10
24
export default function Index ( ) {
25
+ const data = useLoaderData < typeof loader > ( ) ;
26
+ const [ _ , copyToClipboard ] = useCopyToClipboard ( ) ;
27
+
11
28
return (
12
29
< >
13
30
< h1 className = "py-2" > Sharing</ h1 >
14
- < div className = "alert alert-info" >
15
- Coming soon...
16
- </ div >
31
+ < table className = "table table-striped border-top border-bottom" >
32
+ < tbody >
33
+ { data . map ( ( share ) => (
34
+ < tr key = { share . rxs_id } >
35
+ < td > < a href = { `https://next.regexplanet.com/share/index.html?share=${ share . rxs_share_code } ` } > { share . rxs_share_code } </ a >
36
+ < button
37
+ className = "btn btn-sm btn-outline-secondary ms-2 px-1 pt-0 pb-1"
38
+ onClick = { ( ) => copyToClipboard ( `https://next.regexplanet.com/share/index.html?share=${ share . rxs_share_code } ` ) }
39
+ > < PiClipboardBold title = "copy to clipboard" /> </ button >
40
+ </ td >
41
+ < td > { share . rxs_title || share . rxs_regex } </ td >
42
+ < td >
43
+
44
+ < form action = "https://next.regexplanet.com/advanced/java/index.html" className = "d-inline" method = "post" target = "_blank" >
45
+ < input type = "hidden" name = "regex" value = { share . rxs_regex } />
46
+ < input type = "hidden" name = "replacement" value = { share . rxs_replacement || "" } />
47
+ < button className = "btn btn-sm btn-outline-secondary ms-2 px-1 pt-0 pb-1" > < PiPlayBold title = "Test" /> </ button >
48
+ </ form >
49
+ </ td >
50
+
51
+ </ tr >
52
+ ) ) }
53
+ </ tbody >
54
+ </ table >
17
55
</ >
18
56
) ;
19
57
}
0 commit comments