Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Api Server #43

Draft
wants to merge 22 commits into
base: rewrite
Choose a base branch
from
Draft

feature: Api Server #43

wants to merge 22 commits into from

Conversation

l7ssha
Copy link
Member

@l7ssha l7ssha commented Dec 9, 2024

No description provided.

frontend/src/component/NavigationBar.tsx Outdated Show resolved Hide resolved
frontend/src/component/NavigationBar.tsx Outdated Show resolved Hide resolved
frontend/src/component/NavigationBar.tsx Outdated Show resolved Hide resolved
frontend/src/component/NavigationBar.tsx Outdated Show resolved Hide resolved
frontend/src/component/ProtectedRoute.tsx Outdated Show resolved Hide resolved
frontend/src/page/admin/Guilds.tsx Outdated Show resolved Hide resolved
frontend/src/service/auth.ts Outdated Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we use axios?
fetch is globally available.

frontend/src/service/useApi.ts Outdated Show resolved Hide resolved
frontend/src/service/useApi.ts Outdated Show resolved Hide resolved
message: string
}

export async function request<T extends object>({path, method = 'GET', auth = false}: FetchParams) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export async function request<T extends object>({path, method = 'GET', auth = false}: FetchParams) {
export async function request<T extends Record<string | number, unknown> | unknown[]>({path, method = 'GET', auth = false}: FetchParams) {

extends object is certainly not what you want here, with the extends object clause will allow any object, e.g request<string>() is perfectly valid.

export const discordLoginUri = encodeURI(`https://discord.com/oauth2/authorize?client_id=${process.env.REACT_APP_CLIENT_ID}&response_type=code&redirect_uri=${process.env.REACT_APP_REDIRECT_URL}&scope=identify+guilds`);

export function getUserAvatar(id: string, hash: string) {
return `https://media.discordapp.net/avatars/${id}/${hash}.png?size=64`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use the cdn, not the media proxy

Comment on lines 25 to 34
type GuildRowDef = {
id: string,
name: React.JSX.Element|string,
cachedMembers: number,
cachedChannels: number,
cachedMessages: number,
cachedRoles: number,
enabledFeatures: string[],
tagsCount: number,
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
type GuildRowDef = {
id: string,
name: React.JSX.Element|string,
cachedMembers: number,
cachedChannels: number,
cachedMessages: number,
cachedRoles: number,
enabledFeatures: string[],
tagsCount: number,
};
interface GuildRowDef {
id: string,
name: React.JSX.Element|string,
cachedMembers: number,
cachedChannels: number,
cachedMessages: number,
cachedRoles: number,
enabledFeatures: string[],
tagsCount: number,
};

Comment on lines 3 to 18
export type BotInfo = {
nyxxVersion: string;
version: string;
platform: string;
memoryUsageString: string;
cachedChannels: number;
cachedMessages: number;
cachedGuilds: number;
cachedUsers: number;
cachedVoiceStates: number;
shardCount: number;
totalTagsCount: number;
totalReminderCount: number;
uptime: string;
docsUpdate: string;
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export type BotInfo = {
nyxxVersion: string;
version: string;
platform: string;
memoryUsageString: string;
cachedChannels: number;
cachedMessages: number;
cachedGuilds: number;
cachedUsers: number;
cachedVoiceStates: number;
shardCount: number;
totalTagsCount: number;
totalReminderCount: number;
uptime: string;
docsUpdate: string;
};
export interface BotInfo {
nyxxVersion: string;
version: string;
platform: string;
memoryUsageString: string;
cachedChannels: number;
cachedMessages: number;
cachedGuilds: number;
cachedUsers: number;
cachedVoiceStates: number;
shardCount: number;
totalTagsCount: number;
totalReminderCount: number;
uptime: string;
docsUpdate: string;
};

Comment on lines 20 to 31
export type Guild = {
id: string,
name: string,
banner?: string,
icon?: string,
cachedMembers: number,
cachedChannels: number,
cachedMessages: number,
cachedRoles: number,
enabledFeatures: string[],
tagsCount: number,
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export type Guild = {
id: string,
name: string,
banner?: string,
icon?: string,
cachedMembers: number,
cachedChannels: number,
cachedMessages: number,
cachedRoles: number,
enabledFeatures: string[],
tagsCount: number,
};
export interface Guild {
id: string,
name: string,
banner?: string,
icon?: string,
cachedMembers: number,
cachedChannels: number,
cachedMessages: number,
cachedRoles: number,
enabledFeatures: string[],
tagsCount: number,
};

import {Base} from "../component/Base";
import {Container, Grid2, Paper, Typography} from "@mui/material";
import {BotInfoElement} from "../component/BotInfoElement";
import {formatRelative, parseISO} from "date-fns";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We dont need this module

function BotInfoWidget() {
const botInfoStats = use(botInfoStatusPromise);

const uptime = formatRelative(parseISO(botInfoStats.uptime), new Date());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const uptime = formatRelative(parseISO(botInfoStats.uptime), new Date());
const uptime = (new Intl.RelativeTimeFormat('en-GB', { style: 'short' })).format(new Date(botInfoStats.uptime);

Comment on lines +18 to +19
import {parseISO} from "date-fns";
import {format} from "date-fns/format";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We dont need this

Comment on lines +29 to +30
const enabledFeatures = data.enabledFeatures.map(f => {
const enabledAt = format(parseISO(f.enabledAt), 'MM/dd/yyyy');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const enabledFeatures = data.enabledFeatures.map(f => {
const enabledAt = format(parseISO(f.enabledAt), 'MM/dd/yyyy');
const dateFormat = new Intl.DateTimeFormat('en-GB', { dateStyle: 'short', timeStyle: 'short' })
const enabledFeatures = data.enabledFeatures.map(f => {
const enabledAt = dateFormat.format(new Date(f.enabledAt))

Also, using MM/DD/YYY is wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants