Skip to content

Commit 073245f

Browse files
committed
Add links to patterns page
1 parent d80e4a5 commit 073245f

File tree

4 files changed

+73
-50
lines changed

4 files changed

+73
-50
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,23 @@ LATER
4141

4242
## Credits
4343

44+
[![Bootstrap](https://www.vectorlogo.zone/logos/getbootstrap/getbootstrap-ar21.svg)](https://getbootstrap.com/ "HTML/CSS Framework")
4445
[![Google CloudRun](https://www.vectorlogo.zone/logos/google_cloud_run/google_cloud_run-ar21.svg)](https://cloud.google.com/run/ "Hosting")
46+
[![Digital Ocean](https://www.vectorlogo.zone/logos/digitalocean/digitalocean-ar21.svg)](https://m.do.co/c/976f479b2317 "Hosting")
4547
[![Docker](https://www.vectorlogo.zone/logos/docker/docker-ar21.svg)](https://www.docker.com/ "Deployment")
48+
[![Drizzle ORM](https://www.vectorlogo.zone/logos/drizzleteam/drizzleteam-ar21.svg)](https://orm.drizzle.team/ "ORM")
4649
[![Git](https://www.vectorlogo.zone/logos/git-scm/git-scm-ar21.svg)](https://git-scm.com/ "Version control")
4750
[![Github](https://www.vectorlogo.zone/logos/github/github-ar21.svg)](https://github.com/ "Code hosting")
4851
[![Google Noto Emoji](https://www.vectorlogo.zone/logos/google/google-ar21.svg)](https://github.com/googlefonts/noto-emoji/blob/master/svg/emoji_u1f441.svg "Logo/Favicon")
4952
[![Node.js](https://www.vectorlogo.zone/logos/nodejs/nodejs-ar21.svg)](https://nodejs.org/ "Application Server")
5053
[![NodePing](https://www.vectorlogo.zone/logos/nodeping/nodeping-ar21.svg)](https://nodeping.com?rid=201109281250J5K3P "Uptime monitoring")
5154
[![npm](https://www.vectorlogo.zone/logos/npmjs/npmjs-ar21.svg)](https://www.npmjs.com/ "JS Package Management")
5255
[![Phosphor Icons](https://www.vectorlogo.zone/logos/phosphoricons/phosphoricons-ar21.svg)](https://phosphoricons.com/ "Toolbar icons")
56+
[![PostgreSQL](https://www.vectorlogo.zone/logos/postgresql/postgresql-ar21.svg)](https://www.postgresql.org/ "Database")
57+
[![Postgres.js](https://www.vectorlogo.zone/logos/github_postgresjs/github_postgresjs-ar21.svg)](https://github.com/porsager/postgres "Database driver")
5358
[![react.js](https://www.vectorlogo.zone/logos/reactjs/reactjs-ar21.svg)](https://reactjs.org/ "UI Framework")
5459
[![Remix](https://www.vectorlogo.zone/logos/remixrun/remixrun-ar21.svg)](https://remix.run/ "React Framework")
60+
[![SVGR](https://www.vectorlogo.zone/logos/react-svgr/react-svgr-ar21.svg)](https://react-svgr.com/ "SVG conversion")
5561
[![TypeScript](https://www.vectorlogo.zone/logos/typescriptlang/typescriptlang-ar21.svg)](https://www.typescriptlang.org/ "Programming Language")
5662
[![Vite](https://www.vectorlogo.zone/logos/vitejsdev/vitejsdev-ar21.svg)](https://vitejs.dev/ "Bundler")
5763

58-
* [SVGR](https://react-svgr.com/)
59-
* [Drizzle ORM](https://orm.drizzle.team/)
60-
* [Postgres.js](https://github.com/porsager/postgres)

app/routes/patterns._index.tsx

Lines changed: 62 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,79 @@
11
import type { MetaFunction } from "@remix-run/node";
2-
import { Link as RemixLink, useLoaderData } from "@remix-run/react";
2+
import { Link as RemixLink, useLoaderData, useRouteLoaderData } from "@remix-run/react";
33
import { json } from "@remix-run/node";
4+
import { desc, arrayContains } from "drizzle-orm";
45

56
import { getAll, initialize, PatternEntry } from "~/components/Patterns";
67
import { TagList } from "~/components/TagList";
78
import { PatternTagUrlBuilder } from "~/util/PatternTagUrlBuilder";
9+
import LinksTable from "~/components/LinksTable";
10+
import { RootLoaderData } from "~/types/RootLoaderData";
11+
import { dborm } from "~/db/connection.server";
12+
import { regex_link } from "~/db/schema";
813

914
export const loader = async () => {
10-
await initialize();
11-
return json(getAll());
15+
await initialize();
16+
17+
const links = await dborm.select()
18+
.from(regex_link)
19+
.where(arrayContains(regex_link.rxl_tags, ["patterns"]))
20+
.orderBy(desc(regex_link.rxl_created_at))
21+
.limit(100);
22+
23+
return json({
24+
patterns: getAll(),
25+
links,
26+
});
1227
};
1328

1429
export const meta: MetaFunction = () => {
15-
return [
16-
{ title: "Patterns - Regex Zone" },
17-
{ name: "description", content: "A collection of useful regular expression patterns" },
18-
];
30+
return [
31+
{ title: "Patterns - Regex Zone" },
32+
{ name: "description", content: "A collection of useful regular expression patterns" },
33+
];
1934
};
2035

2136
function PatternEntryRow(entry: PatternEntry) {
22-
return (
23-
<tr key={entry.handle}>
24-
<td>
25-
<RemixLink to={`${entry.handle}/`}>{entry.title}</RemixLink>
26-
</td>
27-
<td style={{ 'textAlign': 'right' }}>
28-
{entry.tags ? <TagList tags={entry.tags} urlBuilder={PatternTagUrlBuilder} /> : null}
29-
<div className="badge text-bg-secondary">{entry.variations.length}</div>
30-
</td>
31-
</tr>
32-
);
37+
return (
38+
<tr key={entry.handle}>
39+
<td>
40+
<RemixLink to={`${entry.handle}/`}>{entry.title}</RemixLink>
41+
</td>
42+
<td style={{ 'textAlign': 'right' }}>
43+
{entry.tags ? <TagList tags={entry.tags} urlBuilder={PatternTagUrlBuilder} /> : null}
44+
<div className="badge text-bg-secondary">{entry.variations.length}</div>
45+
</td>
46+
</tr>
47+
);
3348
}
3449

3550
export default function Index() {
36-
const entries = useLoaderData<typeof loader>();
37-
38-
const entryRows = entries.map((entry) => PatternEntryRow(entry));
39-
40-
return (
41-
<>
42-
<h1 className="py-2">Patterns</h1>
43-
<table className="table table-striped table-hover">
44-
<thead>
45-
<tr>
46-
<th>Title</th>
47-
<th>&nbsp;</th>
48-
</tr>
49-
</thead>
50-
<tbody>
51-
{entryRows}
52-
</tbody>
53-
</table>
54-
<details><summary>Raw data</summary>
55-
<pre>{JSON.stringify(entries, null, 4)}</pre>
56-
</details>
57-
</>
58-
);
59-
}
51+
const { user } = useRouteLoaderData<RootLoaderData>("root") as unknown as RootLoaderData;
52+
const data = useLoaderData<typeof loader>();
53+
const links = data.links as unknown as typeof regex_link.$inferSelect[];
54+
55+
const entryRows = data.patterns.map((entry) => PatternEntryRow(entry));
56+
57+
return (
58+
<>
59+
<h1 className="py-2">Patterns</h1>
60+
<table className="table table-striped table-hover">
61+
<thead>
62+
<tr>
63+
<th>Title</th>
64+
<th>&nbsp;</th>
65+
</tr>
66+
</thead>
67+
<tbody>
68+
{entryRows}
69+
</tbody>
70+
</table>
71+
<h2 className="pt-3">Links</h2>
72+
<div className="alert alert-info">Other websites with useful regex patterns</div>
73+
<LinksTable currentUrl="/links/" links={links} isAdmin={user?.isAdmin} />
74+
<details><summary>Raw data</summary>
75+
<pre>{JSON.stringify(data.patterns, null, 4)}</pre>
76+
</details>
77+
</>
78+
);
79+
}

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"@remix-run/express": "^2.11.2",
1515
"@remix-run/node": "^2.9.2",
1616
"@remix-run/react": "^2.9.2",
17-
"@rowanmanning/feed-parser": "^1.1.0",
17+
"@rowanmanning/feed-parser": "^1.1.1",
1818
"@uidotdev/usehooks": "^2.4.1",
1919
"bootstrap": "^5.3.3",
2020
"compression": "^1.7.4",

0 commit comments

Comments
 (0)