Skip to content

Commit

Permalink
import models
Browse files Browse the repository at this point in the history
  • Loading branch information
Hartaithan committed Oct 28, 2023
1 parent f589f19 commit a683118
Show file tree
Hide file tree
Showing 17 changed files with 565 additions and 88 deletions.
46 changes: 46 additions & 0 deletions models/AppModel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import {
type NextComponentType,
type NextPageContext,
type GetServerSidePropsContext,
type NextPage,
} from "next";
import { type AppProps as NextAppProps } from "next/app";
import {
type NullableProfile,
type NullablePSNProfile,
type NullableSession,
} from "./AuthModel";
import { type CSSProperties } from "react";

export type ExtendedPageProps = object;

export interface ExtendedInitialProps {
initialSession: NullableSession;
initialProfile: NullableProfile;
initialPSNProfile: NullablePSNProfile;
isInitialFailed: boolean;
}

export interface AppProps<P = object>
extends NextAppProps<P>,
ExtendedInitialProps {
Component: NextComponentType<
NextPageContext,
ExtendedInitialProps,
ExtendedPageProps
>;
}

export interface InitialProps {
ctx: GetServerSidePropsContext;
}

export type Page<P = object, IP = P> = NextPage<P & ExtendedPageProps, IP>;

export interface CustomPosition {
top?: string | number;
left?: string | number;
bottom?: string | number;
right?: string | number;
transform: CSSProperties["transform"];
}
57 changes: 57 additions & 0 deletions models/AuthModel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { type Session, type User as SupabaseUser } from "@supabase/supabase-js";
import {
type AuthTokensResponse,
type ProfileFromUserNameResponse,
} from "psn-api";

type PSNProfileResponse = ProfileFromUserNameResponse["profile"];
type PersonalDetail = PSNProfileResponse["personalDetail"];

export interface PSNProfile extends Omit<PSNProfileResponse, "personalDetail"> {
personalDetail: PersonalDetail & { middleName: string | undefined };
}

export type NullableSession = Session | null;
export type NullableUser = SupabaseUser | null;
export type NullableProfile = Profile | null;
export type NullablePSNProfile = PSNProfile | null;
export type NullableAuthResponse = AuthTokensResponse | null;

export type ProfileType = "public" | "private";
export type Presence = PSNProfile["presences"][0];

export interface SignUpBody extends Record<string, string> {
email: string;
password: string;
npsso: string;
language: string;
username: string;
type: ProfileType;
}

interface UserData {
language: string;
username: string;
onlineId: string;
type: ProfileType;
}

export interface User extends SupabaseUser {
user_metadata: SupabaseUser["user_metadata"] & UserData;
}

export interface Profile {
id: string;
created_at: string;
language: string;
username: string;
online_id: string;
type: ProfileType;
}

export type ProfileEditBody = Pick<Profile, "language" | "type">;

export interface SessionResponse {
session: NullableSession;
profile: NullableProfile;
}
17 changes: 17 additions & 0 deletions models/BoardModel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { type MantineColor } from "@mantine/core";
import { type Game } from "./GameModel";
import { type Range } from "./UtilsModel";

export interface ColumnColor {
color: MantineColor;
shade: Range<0, 10>;
}

export enum BOARD_COLUMNS {
Backlog = "backlog",
InProgress = "progress",
Platinum = "platinum",
Complete = "complete",
}

export type BoardColumns = Record<BOARD_COLUMNS | string, Game[]>;
43 changes: 43 additions & 0 deletions models/GameModel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { type BOARD_COLUMNS } from "./BoardModel";
import { type Platform } from "./PlatformModel";
import { type ProgressItem } from "./ProgressModel";

export interface Game {
id: number;
created_at: string;
updated_at: string;
title: string;
image_url: string;
platform: Platform;
status: BOARD_COLUMNS;
progress: ProgressItem[] | null;
user_id: string;
username: string;
code: string;
position: number;
}

export type NewGamePayload = Omit<
Game,
"id" | "created_at" | "updated_at" | "progress" | "position"
>;

export interface AddGamePayload {
game_id: string;
status: BOARD_COLUMNS;
}

export interface AddGameState {
status: BOARD_COLUMNS | null;
opened: boolean;
}

export interface ReorderItem {
id: number;
position: number;
status: BOARD_COLUMNS;
}

export interface ReorderPayload {
items: ReorderItem[];
}
6 changes: 6 additions & 0 deletions models/LinkModel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface HeaderLink {
id: number;
label: string;
href: string;
disabled: boolean;
}
6 changes: 6 additions & 0 deletions models/LocaleModel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface Locale {
id: number;
value: string;
label: string;
icon_url: string;
}
8 changes: 8 additions & 0 deletions models/ModalModel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { type Dispatch, type SetStateAction } from "react";

interface DefaultModalProps {
opened: boolean;
setOpened: Dispatch<SetStateAction<boolean>>;
}

export type ModalProps<T = object> = T & DefaultModalProps;
35 changes: 35 additions & 0 deletions models/NoteModel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { type Dispatch, type SetStateAction } from "react";

export interface Note {
id: number;
created_at: string;
updated_at: string;
user_id: string;
username: string;
game_id: number;
trophy_id: number;
content: string;
}

export interface AddNotePayload {
game_id: number;
trophy_id: number;
content: string;
}

export interface NewNotePayload
extends Omit<Note, "id" | "created_at" | "updated_at" | "content"> {
content: string | null;
}

export interface NoteModalState {
opened: boolean;
game_id: number | null;
trophy_id: number | null;
}

export interface NoteModalHandler extends NoteModalState {
setState: Dispatch<SetStateAction<NoteModalState>>;
open: (params?: Partial<NoteModalState>) => void;
close: () => void;
}
11 changes: 11 additions & 0 deletions models/PlatformModel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export type Platform = "ps3" | "ps4" | "ps5" | "vita" | string;

export interface PlatformLabel {
short: string;
full: string;
}

export interface PlatformColor {
bg: string;
fg: string;
}
21 changes: 21 additions & 0 deletions models/ProgressModel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export interface ProgressItem {
id: number;
earned: boolean;
group: string;
dlc: boolean;
}

export interface ProgressPayload {
payload: ProgressItem[];
}

export type ProgressType = "platinum" | "complete";

export interface ProgressStats {
base: number;
baseCompleted: number;
baseProgress: number;
total: number;
totalCompleted: number;
totalProgress: number;
}
25 changes: 25 additions & 0 deletions models/SearchModel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export interface SearchQueries {
[key: string]: string | string[];
query: string;
}

export interface SearchItem {
id: string;
title: string;
platform_title: string;
count_tlist: number;
count_article: number;
release_date: string;
}

export interface SearchResult {
id: number;
name: string;
platform: string;
url: string;
}

export interface SearchResponse {
query: string;
results: SearchResult[];
}
5 changes: 5 additions & 0 deletions models/ThemeModel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { type MantineTheme } from "@mantine/core";

export type DefaultProps<P> =
| Partial<P>
| ((theme: MantineTheme) => Partial<P>);
Loading

0 comments on commit a683118

Please sign in to comment.