-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR connects pano to GQL. Closes #544 Closes #545 Closes #582 Closes #588 Closes #589 Closes #590
- Loading branch information
Showing
31 changed files
with
630 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { type Clients } from "./clients"; | ||
import { createPanoActions } from "./features/pano/post"; | ||
|
||
export type DataActions = ReturnType<typeof createActions>; | ||
|
||
export function createActions(clients: Clients) { | ||
return { | ||
pano: createPanoActions(clients), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const makeErrorFactory = | ||
<T extends string>(__typename: T, defaultValue: string) => | ||
(message = defaultValue) => ({ __typename, message }); | ||
|
||
export const NotAuthorized = makeErrorFactory("NotAuthorized", "Not authorized"); | ||
export const InvalidInput = makeErrorFactory("InvalidInput", "Invalid input"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { type Clients } from "~/clients"; | ||
import { getSitename } from "./utils/get-sitename"; | ||
|
||
export function createPanoActions(clients: Clients) { | ||
return { | ||
post: createPanoPostActions(clients), | ||
}; | ||
} | ||
|
||
interface CreatePanoPostArgs { | ||
title: string; | ||
userID: string; | ||
url: string | null; | ||
content: string | null; | ||
} | ||
|
||
interface UpdatePanoPostArgs { | ||
title: string; | ||
url: string | null; | ||
content: string | null; | ||
} | ||
|
||
function createPanoPostActions({ prisma }: Clients) { | ||
const create = (args: CreatePanoPostArgs) => { | ||
return prisma.post.create({ | ||
data: { | ||
title: args.title, | ||
url: args.url, | ||
site: getSitename(args.url), | ||
content: args.content, | ||
owner: { connect: { id: args.userID } }, | ||
}, | ||
}); | ||
}; | ||
|
||
const update = (id: string, args: UpdatePanoPostArgs) => { | ||
return prisma.post.update({ | ||
where: { id }, | ||
data: { | ||
title: args.title, | ||
url: args.url, | ||
site: getSitename(args.url), | ||
content: args.content, | ||
}, | ||
}); | ||
}; | ||
|
||
const remove = (id: string) => { | ||
return prisma.post.delete({ where: { id } }); | ||
}; | ||
|
||
return { | ||
create, | ||
update, | ||
remove, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { describe, expect, it } from "vitest"; | ||
|
||
import { getSitename } from "./get-sitename"; | ||
|
||
describe(getSitename, () => { | ||
it("returns undefined when href is null", () => { | ||
expect(getSitename(null)).toBeUndefined(); | ||
}); | ||
|
||
it("returns hostname of when href is a correct url", () => { | ||
expect(getSitename("https://kamp.us/foo/bar/baz")).toBe("kamp.us"); | ||
}); | ||
|
||
it.each(["twitch.tv", "twitter.com", "github.com"])( | ||
"uses overrides withUsername override for %j", | ||
(override) => { | ||
const href = `https://${override}/username/foo/bar`; | ||
expect(getSitename(href)).toBe(`${override}/username`); | ||
} | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
interface Override { | ||
execute: (url: URL) => string; | ||
} | ||
|
||
const withUsername = { | ||
execute(url) { | ||
const [, username] = url.pathname.split("/"); | ||
return `${url.hostname}/${username}`; | ||
}, | ||
} satisfies Override; | ||
|
||
const overrides: Record<string, Override> = { | ||
"twitch.tv": withUsername, | ||
"twitter.com": withUsername, | ||
"github.com": withUsername, | ||
}; | ||
|
||
export const getSitename = (href: string | null) => { | ||
if (!href) { | ||
return; | ||
} | ||
|
||
const url = new URL(href); | ||
return overrides[url.hostname]?.execute(url) ?? url.hostname; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.