11import 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" ;
29
310export const meta : MetaFunction = ( ) => {
411 return [
@@ -7,13 +14,44 @@ export const meta: MetaFunction = () => {
714 ] ;
815} ;
916
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+
1024export default function Index ( ) {
25+ const data = useLoaderData < typeof loader > ( ) ;
26+ const [ _ , copyToClipboard ] = useCopyToClipboard ( ) ;
27+
1128 return (
1229 < >
1330 < 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 >
1755 </ >
1856 ) ;
1957}
0 commit comments