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

chore/eslint v9 #76

Merged
merged 21 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .eslintrc.cjs

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

*.cookie
# dependencies
node_modules
.pnp
Expand Down
4 changes: 0 additions & 4 deletions apps/api/.eslintrc.cjs

This file was deleted.

14 changes: 14 additions & 0 deletions apps/api/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import baseConfig from "lint/node.js";
import tseslint from "typescript-eslint";

const config = tseslint.config(
...baseConfig,
{
ignores: [".wrangler"],
},
{
rules: {},
},
);

export default config;
3 changes: 1 addition & 2 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"deploy": "wrangler deploy",
"build": "wrangler deploy --dry-run --outdir=dist",
"lint": "eslint . --ext .js,.ts",
"lint": "eslint",
"check:format": "prettier --check \"**/*.{ts,js,md}\"",
"clean": "rm -rf dist .turbo node_modules",
"format": "prettier --write .",
Expand All @@ -18,7 +18,6 @@
"lint": "workspace:*",
"types": "workspace:*",
"tsconfig": "workspace:*",
"typescript": "^5.4.2",
"wrangler": "^3.32.0"
},
"dependencies": {
Expand Down
2 changes: 0 additions & 2 deletions apps/api/src/handlers/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ app.get("/latest", async (c) => {

app.get("/:target/:arch/:currentVersion", async (c) => {
// TODO: updater metrics maybe?
const target = c.req.param("target");
const arch = c.req.param("arch");
const currentVersion = c.req.param("currentVersion");

try {
Expand Down
9 changes: 0 additions & 9 deletions apps/desktop/.eslintrc.cjs

This file was deleted.

16 changes: 16 additions & 0 deletions apps/desktop/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import tseslint from "typescript-eslint";

import baseConfig from "lint/node.js";

// TODO: make work for next
const config = tseslint.config(
...baseConfig,
{
ignores: ["src-tauri/"],
},
{
rules: {},
}
);

export default config;
3 changes: 1 addition & 2 deletions apps/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"start": "tauri dev",
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint 'src/**/*' --ext .js,.jsx,.ts,.tsx",
"lint": "eslint",
"clean": "rm -rf dist .turbo node_modules",
"check:format": "prettier --check 'src/**/*.{ts,js,tsx,jsx}'",
"format": "prettier --write .",
Expand Down Expand Up @@ -54,7 +54,6 @@
"postcss": "^8.4.35",
"tailwindcss": "^3.4.1",
"tsconfig": "workspace:*",
"typescript": "^5.4.2",
"vite": "^5.1.5"
}
}
12 changes: 10 additions & 2 deletions apps/desktop/src/components/nav-bar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { useLocation, useNavigate } from "react-router-dom";
import { Settings, Pin, Download, ArrowLeftToLine, ArrowRightToLine, ChevronsRightLeft } from "lucide-react";
import {
Settings,
Pin,
Download,
ArrowLeftToLine,
ArrowRightToLine,
ChevronsRightLeft,
type LucideIcon,
} from "lucide-react";

import React from "react";
import { invoke } from "@tauri-apps/api";
Expand All @@ -16,7 +24,7 @@ const mapping = {
interface Alignment {
direction: DirectionLR;
name: string;
icon: React.FC<any>;
icon: LucideIcon;
}

const horizontalAlignments: Alignment[] = [
Expand Down
1 change: 0 additions & 1 deletion apps/desktop/src/components/ui/dialog.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable react/prop-types */
import * as React from "react";
import * as DialogPrimitive from "@radix-ui/react-dialog";
import { X } from "lucide-react";
Expand Down
1 change: 1 addition & 0 deletions apps/desktop/src/components/ui/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from "react";

import { cn } from "@/lib/utils";

// eslint-disable-next-line @typescript-eslint/no-empty-object-type
export interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {}

const Input = React.forwardRef<HTMLInputElement, InputProps>(({ className, type, ...props }, ref) => {
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src/components/updater.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const Updater = ({
</DialogTrigger>
<DialogContent className="w-[80%]">
<form
onSubmit={async _event => {
onSubmit={async () => {
// TODO:
console.log("installing update");
try {
Expand Down
4 changes: 2 additions & 2 deletions apps/desktop/src/components/user.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ export const User = ({ item, alignDirection }: { item: OverlayedUser; alignDirec
<div className={`pointer-events-none relative rounded-full border-2 ${avatarClass} ${talkingClass}`}>
<img
onError={e => {
// @ts-ignore
// @ts-expect-error need to fix this prolly
e.target.onerror = null;
// @ts-ignore
// @ts-expect-error need to fix this prolly
e.target.src = "/img/default.png";
}}
src={avatarUrl}
Expand Down
8 changes: 5 additions & 3 deletions apps/desktop/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,27 @@ export class Config {
...this.config,
// NOTE: set new keys added to the default value
...newKeys.reduce((acc, key) => {
// @ts-ignore
// @ts-expect-error not sure why this errors but need to fix it
acc[key] = DEFAULT_OVERLAYED_CONFIG[key as OverlayedConfigKey];
return acc;
}, {} as OverlayedConfig),
};

// fuck it persist it
this.save();
} catch (e) {
} catch (e: unknown) {
this.config = DEFAULT_OVERLAYED_CONFIG;
this.save();

console.error(e);
}
};

getConfig(): OverlayedConfig {
return this.config;
}

get(key: OverlayedConfigKey): any | null {
get<K extends keyof OverlayedConfig>(key: K): OverlayedConfig[K] | null {
return this.config[key] || null;
}

Expand Down
1 change: 1 addition & 0 deletions apps/desktop/src/hooks/use-config-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ export const useConfigValue = <T>(
};
}, []);

// @ts-expect-error need to fix this?
return { value };
};
6 changes: 5 additions & 1 deletion apps/desktop/src/rpc/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { RPCErrors } from "./errors";
import { MetricNames, track, trackEvent } from "@/metrics";
import { emit } from "@tauri-apps/api/event";
import { Event } from "@/constants";
import type { VoiceUser } from "@/types";

interface TokenResponse {
access_token: string;
Expand Down Expand Up @@ -39,7 +40,7 @@ class UserdataStore {
this.store.setItem(this.keys.accessTokenExpiry, dateString);
}

setUserdata(userdata: any) {
setUserdata(userdata: VoiceUser) {
this.store.setItem(this.keys.userData, JSON.stringify(userdata));
}

Expand Down Expand Up @@ -67,7 +68,9 @@ const STREAMKIT_URL = "https://streamkit.discord.com";
interface DiscordPayload {
cmd: `${RPCCommand}`;
// TODO: how do i type this properly?
// eslint-disable-next-line @typescript-eslint/no-explicit-any
args?: any;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
data?: any;
evt?: `${RPCEvent}` | null;
nonce?: string;
Expand Down Expand Up @@ -232,6 +235,7 @@ class SocketManager {
// try to find the user
this.requestUserChannel();

// TODO: is this needed cause it's just the id for some reason
this.store.setCurrentChannel(payload.data.channel_id);
if (payload.data?.channel_id) {
this.send({
Expand Down
19 changes: 6 additions & 13 deletions apps/desktop/src/store.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { create } from "zustand";
import type { OverlayedUser, VoiceStateUser } from "./types";
import type { CurrentChannel, OverlayedUser, VoiceStateUser } from "./types";
import { immer } from "zustand/middleware/immer";
import { enableMapSet } from "immer";

Expand Down Expand Up @@ -32,12 +32,8 @@ export const createUserStateItem = (payload: VoiceStateUser) => {
export interface AppState {
visible: boolean;
clickThrough: boolean;
// TODO: type this better
me: any | null;
currentChannel: {
id: string;
name: string;
} | null;
me: OverlayedUser | null;
currentChannel: CurrentChannel | null;
users: Record<string, OverlayedUser>;
discordErrors: Set<string>;
}
Expand All @@ -51,8 +47,7 @@ export interface AppActions {
clearUsers: () => void;
removeUser: (id: string) => void;
addUser: (user: VoiceStateUser) => void;
// TODO: type this
setCurrentChannel: (channel: any) => void;
setCurrentChannel: (channel: CurrentChannel | null) => void;
setMe: (user: OverlayedUser | null) => void;
pushError: (message: string) => void;
resetErrors: () => void;
Expand All @@ -69,7 +64,7 @@ const sortUserList = (myId: string | undefined, users: VoiceStateUser[]) => {
});

const userMapSorted: Record<string, OverlayedUser> = {};
for (const [_, item] of sortedUserArray) {
for (const [, item] of sortedUserArray) {
userMapSorted[item.user.id] = createUserStateItem(item);
}

Expand All @@ -87,7 +82,7 @@ const sortOverlayedUsers = (myId: string | undefined, users: Record<string, Over
});

const userMapSorted: Record<string, OverlayedUser> = {};
for (const [_, item] of sortedUserArray) {
for (const [, item] of sortedUserArray) {
userMapSorted[item.id] = item;
}

Expand All @@ -96,8 +91,6 @@ const sortOverlayedUsers = (myId: string | undefined, users: Record<string, Over

// TODO: split this into multiple stores
export const useAppStore = create<AppState & AppActions>()(
// TODO: fix later
// @ts-ignore
immer(set => ({
visible: true,
me: null,
Expand Down
13 changes: 9 additions & 4 deletions apps/desktop/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface OverlayedUser {
*/
avatarHash: string;

avatarDecorationData: any;
avatarDecorationData: unknown;

/**
* @property {boolean} talking - flag to indicate if the user is talking
Expand Down Expand Up @@ -83,6 +83,11 @@ export interface OverlayedUser {
lastUpdate: number;
}

export interface CurrentChannel {
id: string;
name: string;
}

export interface VoiceStateData {
nick: string;
mute: boolean;
Expand All @@ -101,7 +106,7 @@ export interface ChannelJoinEvent {
user_limit: string;
guild_id: string;
position: number;
messages: any;
messages: unknown[];
voice_states: VoiceStateData[];
}

Expand All @@ -119,9 +124,9 @@ interface VoiceState {
}

// TODO: name these better
interface VoiceUser {
export interface VoiceUser {
avatar: string;
avatar_decoration_data: any;
avatar_decoration_data: unknown;
bot: boolean;
discriminator: string;
flags: number;
Expand Down
6 changes: 3 additions & 3 deletions apps/desktop/src/views/channel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import { useConfigValue } from "@/hooks/use-config-value";
export const ChannelView = ({ alignDirection }: { alignDirection: DirectionLR }) => {
const { users, me } = useAppStore();

const { value: showOnlyTalkingUsers } = useConfigValue<boolean>("showOnlyTalkingUsers");
const { value: showOnlyTalkingUsers } = useConfigValue("showOnlyTalkingUsers");

const allUsers = Object.entries(users);
const userList = showOnlyTalkingUsers ? allUsers.filter(([_, item]) => item.talking || item.id === me.id) : allUsers;
const userList = showOnlyTalkingUsers ? allUsers.filter(([, item]) => item.talking || item.id === me?.id) : allUsers;

return (
<div>
<div className={`py-2 ${alignDirection == "center" ? "flex flex-wrap justify-center" : ""}`}>
{userList.map(([_, item]) => (
{userList.map(([, item]) => (
<User key={item.id} item={item} alignDirection={alignDirection} />
))}
</div>
Expand Down
6 changes: 3 additions & 3 deletions apps/desktop/src/views/settings/account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ import { useEffect, useState } from "react";
import { Checkbox } from "@/components/ui/checkbox";
import { emit } from "@tauri-apps/api/event";
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
import type { VoiceUser } from "@/types";

export const Developer = () => {
const platformInfo = usePlatformInfo();
const [showOnlyTalkingUsers, setShowOnlyTalkingUsers] = useState(Config.get("showOnlyTalkingUsers"));
const [showOnlyTalkingUsers, setShowOnlyTalkingUsers] = useState(Config.get("showOnlyTalkingUsers")!);

return (
<>
Expand Down Expand Up @@ -99,8 +100,7 @@ export const Developer = () => {
export const Account = () => {
const [showLogoutDialog, setShowLogoutDialog] = useState(false);
const [showQuitDialog, setShowQuitDialog] = useState(false);
// TODO: type this
const [user, setUser] = useState<any>(null);
const [user, setUser] = useState<VoiceUser | null>(null);
const [tokenExpires, setTokenExpires] = useState(localStorage.getItem("discord_access_token_expiry"));

// pull out the user data from localStorage
Expand Down
Loading