diff --git a/src/pages/profiles/[id].astro b/src/pages/profiles/[id].astro new file mode 100644 index 0000000..1d70620 --- /dev/null +++ b/src/pages/profiles/[id].astro @@ -0,0 +1,97 @@ +--- +import Avatar from "../../components/Avatar.astro"; +import Layout from "../../layouts/Layout.astro"; +import { + getAllChecksByUser, + getCheckRevision, + getProfileById, + getTemplateRevision, +} from "../../backendlib"; +import CheckCard from "../../components/CheckCard.astro"; +import { + decodeKinkCheck, + type check, + type check_revision, + type TemplateRevision, +} from "../../base"; + +const { id } = Astro.params; + +if (!id) { + return new Response("no user id given", { status: 400 }); +} + +const [profile, error] = await getProfileById(id); + +if (error) { + return new Response(error.message, { status: 500 }); +} + +const [checks, err] = await getAllChecksByUser(id); +const usableChecks = + checks && + (await Promise.all( + checks + .map((x) => getCheckRevision(x, "latest")) + .filter((x) => x) + .map((x) => x!) + .map>( + async (check) => [ + check, + await getTemplateRevision({ + id: check.template, + version: check.version, + }).then(([t]) => t), + ], + ), + )); +--- + + + + Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor + incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud + exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute + irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat + nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa + qui officia deserunt mollit anim id est laborum. + +

Checks

+ { + err || !checks.length || !usableChecks ? ( + <> +

+ There are no checks from this user (or they aren't visible + to you) +

+
{err}
+ + ) : ( +
    + {usableChecks.map(([check, template]) => + !template ? ( +
  • + Can't load template (TODO: display error): {check} +
  • + ) : ( + // TODO: when it's the user's own profile we might want to link to the template + + ), + )} +
+ ) + } +
+ + diff --git a/src/pages/templates/[id]/checks/[user]/index.astro b/src/pages/templates/[id]/checks/[user]/index.astro new file mode 100644 index 0000000..27cfdc5 --- /dev/null +++ b/src/pages/templates/[id]/checks/[user]/index.astro @@ -0,0 +1,85 @@ +--- +import { + getCheck, + getCheckRevision, + getProfileById, + getTemplateRevision, +getUserIdByName, +} from "../../../../../backendlib"; +import { decodeKinkCheck, defaultRatings, prettyDate } from "../../../../../base"; +import { Check } from "../../../../../components/KinkCheck"; +import RatingOverview from "../../../../../components/RatingOverview.astro"; +import Layout from "../../../../../layouts/Layout.astro"; + +const { id, user } = Astro.params; + +if (!id || !user) { + return new Response(`no ${!id ? "template id" : "user"} given`, { + status: 400, + }); +} + +if (user.startsWith("@")) { + const [id, error] = await getUserIdByName(user.substring(1)); + if (error) { + return Response(error.message, { code: 500 }); + } + const url = Astro.url; + url.pathname = url.pathname.replace(user, id); + return Astro.redirect(url); +} + +const [profile] = await getProfileById(user); + +const [check, err] = await getCheck({ user, template: id }); + +if (err) { + return new Response(err.message, { status: 500 }); +} + +const rev = getCheckRevision(check, "latest"); + +const [template, error] = await getTemplateRevision({ + id, + version: rev?.version ?? "latest", +}); + +if (error) { + return new Response(error.message, { status: 500 }); +} + +// TODO: selecting revisions, ........ +// TODO: when self maybe display and edit button +--- + + + + from {profile ? profile.full_name : user} + {rev && prettyDate(new Date(rev.modified))} + + +
+ +
+
+ +