Skip to content

Commit 5e6dd2c

Browse files
committed
Sharing page
1 parent a4470c0 commit 5e6dd2c

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44

55
A collection of useful regular expressions and related resources.
66

7+
## Running
8+
9+
To install the database:
10+
```
11+
npx drizzle-kit generate
12+
npx drizzle-kit migrate
13+
```
14+
715
## License
816

917
CC BY-SA 4.0: [Overview](https://creativecommons.org/licenses/by-sa/4.0/), [Full text](LICENSE.txt)

app/routes/sharing._index.tsx

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
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";
29

310
export 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+
1024
export 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

Comments
 (0)