Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"dayjs": "^1.11.13",
"lucide-react": "^0.542.0",
"next": "^15.4.0",
"pathcat": "^1.4.0",
"pathcat": "^1.5.1",
"react": "^19",
"react-dom": "^19",
"react-grid-gallery": "^1.0.1"
Expand Down
1 change: 0 additions & 1 deletion src/app/about/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { pathWildcat } from "@/spanner/api";
import { Metadata } from "next";
import Image from "next/image";
import { cloneElement } from "react";
Expand Down
4 changes: 2 additions & 2 deletions src/app/join/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { pathWildcat } from "@/spanner/api";
import { spannerPathCat } from "@/spanner/api";
import { wwlrcClubId } from "@/spanner/wwlrc";
import { Download, ExternalLinkIcon } from "lucide-react";
import { Metadata } from "next";
Expand Down Expand Up @@ -178,7 +178,7 @@ export default function Join() {
</p>
<p className="mb-3">
<a
href={pathWildcat("clubs/c/:clubId/membership_request", {
href={spannerPathCat("clubs/c/:clubId/membership_request", {
clubId: wwlrcClubId,
})}
target="_blank"
Expand Down
47 changes: 31 additions & 16 deletions src/spanner/api.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
import { pathcat, Query } from "pathcat";
import { base, ExtractRouteParams, Query, pathcat } from "pathcat";

const spannerBase = "https://spanner.wwlrc.co.uk";
export const spannerPathCat = base("https://spanner.wwlrc.co.uk");

export function pathWildcat(template: string, query?: Query<string>): string {
if (!query) {
return pathcat(spannerBase, template);
}

return pathcat(spannerBase, template, query);
function wrap<R>(
fn: (path: string) => R,
): <Path extends string>(
base: string,
path: Path,
...query: [ExtractRouteParams<Path>] extends [never]
? [query?: Query<Path>]
: [query: Query<Path>]
) => R {
return (base, path, ...query): R => fn(pathcat(base, path, ...query));
}

export function spannerApiFetch(
template: string,
query?: Query<string>,
): Promise<any> {
const url = pathWildcat(template, query);
let p = fetch(url);
// TODO: probably worth putting some more fancy error handling here
return p.then((response) => response.json());
function wrapWithBase<R>(
base: string,
fn: (path: string) => R,
): <Path extends string>(
path: Path,
...query: [ExtractRouteParams<Path>] extends [never]
? [query?: Query<Path>]
: [query: Query<Path>]
) => R {
return (path, ...query): R => wrap(fn)(base, path, ...query);
}

export const spannerApiFetch = wrapWithBase<Promise<any>>(
"https://spanner.wwlrc.co.uk",
async (path) => {
let response = await fetch(path);
// TODO: probably worth putting some more fancy error handling here
return response.json();
},
);
2 changes: 1 addition & 1 deletion src/spanner/blog.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { spannerApiFetch } from "./api";
import { spannerApiFetch, spannerPathCat } from "./api";
import { wwlrcClubId } from "./wwlrc";

export async function getPosts(): Promise<any[]> {
Expand Down