feat: add go users exporter
This commit is contained in:
parent
6388e3127d
commit
41e620ad03
7 changed files with 629 additions and 7 deletions
|
@ -1,13 +1,49 @@
|
|||
export type User = {
|
||||
export type PartialUser = {
|
||||
id: string;
|
||||
username: string;
|
||||
display_name: string | null;
|
||||
display_name?: string | null;
|
||||
avatar_url?: string | null;
|
||||
};
|
||||
|
||||
export type User = PartialUser & {
|
||||
bio: string | null;
|
||||
member_title: string | null;
|
||||
avatar_url: string | null;
|
||||
links: string[];
|
||||
names: FieldEntry[];
|
||||
pronouns: Pronoun[];
|
||||
fields: Field[];
|
||||
};
|
||||
|
||||
export type UserWithMembers = User & { members: PartialMember[] };
|
||||
|
||||
export type UserWithHiddenFields = User & {
|
||||
auth_methods?: unknown[];
|
||||
member_list_hidden: boolean;
|
||||
last_active: string;
|
||||
};
|
||||
|
||||
export type UserSettings = {
|
||||
dark_mode: boolean | null;
|
||||
};
|
||||
|
||||
export type PartialMember = {
|
||||
id: string;
|
||||
name: string;
|
||||
display_name: string | null;
|
||||
bio: string | null;
|
||||
avatar_url: string | null;
|
||||
names: FieldEntry[];
|
||||
pronouns: Pronoun[];
|
||||
};
|
||||
|
||||
export type FieldEntry = {
|
||||
value: string;
|
||||
status: string;
|
||||
};
|
||||
|
||||
export type Pronoun = FieldEntry & { display_text: string | null };
|
||||
|
||||
export type Field = {
|
||||
name: string;
|
||||
entries: FieldEntry[];
|
||||
};
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { json, LoaderFunctionArgs, MetaFunction } from "@remix-run/node";
|
||||
import { redirect, useLoaderData } from "@remix-run/react";
|
||||
import { User } from "~/lib/api/user";
|
||||
import { UserWithMembers } from "~/lib/api/user";
|
||||
import serverRequest from "~/lib/request.server";
|
||||
|
||||
export const meta: MetaFunction<typeof loader> = ({ data }) => {
|
||||
|
@ -9,14 +9,19 @@ export const meta: MetaFunction<typeof loader> = ({ data }) => {
|
|||
return [{ title: `@${user.username} - pronouns.cc` }];
|
||||
};
|
||||
|
||||
export const loader = async ({ params }: LoaderFunctionArgs) => {
|
||||
export const loader = async ({ request, params }: LoaderFunctionArgs) => {
|
||||
const url = new URL(request.url);
|
||||
const memberPage = parseInt(url.searchParams.get("page") ?? "0", 10);
|
||||
|
||||
let username = params.username!;
|
||||
if (!username.startsWith("@")) throw redirect(`/@${username}`);
|
||||
username = username.substring("@".length);
|
||||
|
||||
const user = await serverRequest<User>("GET", `/users/${username}`);
|
||||
const user = await serverRequest<UserWithMembers>("GET", `/users/${username}`);
|
||||
let members = user.members.slice(memberPage * 20, (memberPage + 1) * 20);
|
||||
if (members.length === 0) members = user.members.slice(0, 20);
|
||||
|
||||
return json({ user });
|
||||
return json({ user, members });
|
||||
};
|
||||
|
||||
export default function UserPage() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue