diff --git a/src/app/api/profile/route.ts b/src/app/api/profile/route.ts
index e45c823..46238aa 100644
--- a/src/app/api/profile/route.ts
+++ b/src/app/api/profile/route.ts
@@ -19,7 +19,14 @@ export async function POST(req: NextRequest) {
{ status: StatusCodes.BAD_REQUEST }
);
- if (!username || !display_name || !avatar_url)
+ if (
+ !username ||
+ !display_name ||
+ avatar_url === undefined ||
+ avatar_url === null ||
+ node_address === undefined ||
+ node_address === null
+ )
return NextResponse.json(
{
message:
diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsx
index 66e0830..9d1a313 100644
--- a/src/components/Sidebar.tsx
+++ b/src/components/Sidebar.tsx
@@ -36,6 +36,7 @@ import Link from "next/link";
import { get, Response } from "@/lib/request";
import { cn } from "@/lib/utils";
import App from "@/types/app";
+import { ProfileSettings } from "@/types/settings";
export default function AppSidebar({
children,
@@ -201,7 +202,7 @@ export default function AppSidebar({
@@ -243,6 +244,7 @@ export default function AppSidebar({
?.avatar_url || ""
}
key={id}
+ app={app}
/>
))}
>
@@ -256,6 +258,7 @@ export default function AppSidebar({
id={app.profile?.id || "me"}
avatar={app.profile?.avatar_url || ""}
status="online"
+ app={app}
settings
/>
@@ -283,12 +286,14 @@ function DMItem({
avatar,
status,
settings,
+ app,
}: {
name: string;
id: string;
avatar: string;
status: string;
settings?: boolean;
+ app: App;
}) {
return (
)}
@@ -332,10 +338,12 @@ function ChannelIcon({ kind }: { kind: "text" | "voice" }) {
function getUser(
id: string,
- userList: StringMap,
- setUserList: React.Dispatch>>
+ userList: StringMap,
+ setUserList: React.Dispatch<
+ React.SetStateAction>
+ >
) {
- if (userList[id]) return userList[id];
+ if (userList[id] !== undefined) return userList[id];
const onResponse = (res: Response) => {
setUserList((prev) => {
@@ -346,5 +354,10 @@ function getUser(
get(`/api/profile/?id=${id}`, onResponse)
?.then(onResponse)
- .catch((e) => {});
+ .catch((e) => {
+ setUserList((prev) => {
+ prev[id] = null;
+ return prev;
+ });
+ });
}
diff --git a/src/components/settings/Settings.tsx b/src/components/settings/Settings.tsx
index 6842abf..78b02f2 100644
--- a/src/components/settings/Settings.tsx
+++ b/src/components/settings/Settings.tsx
@@ -1,6 +1,5 @@
"use client";
-import { useClientSettings } from "@/hooks/use-settings";
import { setClientSettings } from "@/lib/clientSettings";
import SettingSchema from "./SettingSchema";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
@@ -11,19 +10,20 @@ import {
CLIENT_SCHEMA,
ProfileSettings,
} from "@/types/settings";
-import { useParams, useRouter, useSearchParams } from "next/navigation";
+import { useRouter } from "next/navigation";
import axios from "axios";
+import { useClientSettings } from "@/hooks/use-settings";
+import { useState } from "react";
export default function Settings({
tab,
- profileSettings,
- setProfileSettings,
+ profileSettings: ps,
}: {
tab?: string;
profileSettings: ProfileSettings;
- setProfileSettings: React.Dispatch>;
}) {
const [settings, setSettings] = useClientSettings();
+ const [profileSettings, setProfileSettings] = useState(ps);
const router = useRouter();
return (
diff --git a/src/components/settings/SettingsDialog.tsx b/src/components/settings/SettingsDialog.tsx
index 4d98415..6ed0225 100644
--- a/src/components/settings/SettingsDialog.tsx
+++ b/src/components/settings/SettingsDialog.tsx
@@ -3,7 +3,6 @@ import { Button } from "../ui/button";
import {
Dialog,
DialogContent,
- DialogDescription,
DialogHeader,
DialogTitle,
DialogTrigger,
@@ -11,18 +10,17 @@ import {
import { cn } from "@/lib/utils";
import Settings from "./Settings";
import { ProfileSettings } from "@/types/settings";
-import { useProfileSettings } from "@/hooks/use-settings";
+import { useState } from "react";
export default function SettingsDialog({
className,
tab,
+ profile,
}: {
className?: string;
tab?: string;
- profile?: ProfileSettings;
+ profile: ProfileSettings;
}) {
- const [profileSettings, setProfileSettings] = useProfileSettings();
-
return (
diff --git a/src/hooks/use-app.ts b/src/hooks/use-app.ts
index fa4af8d..7285484 100644
--- a/src/hooks/use-app.ts
+++ b/src/hooks/use-app.ts
@@ -6,7 +6,7 @@ import useUser, { UserProfile } from "./get-user";
export default function useApp(): App {
const node = useRef(null);
- const [profiles, setProfiles] = useState>({});
+ const [profiles, setProfiles] = useState>({});
const { messages, addMessage } = useMessages();
const [sidebarOpen, setSidebarOpen] = useState(true);
const profile = useUser();
diff --git a/src/hooks/use-settings.ts b/src/hooks/use-settings.ts
index 21bf861..a4e51f5 100644
--- a/src/hooks/use-settings.ts
+++ b/src/hooks/use-settings.ts
@@ -1,8 +1,7 @@
"use client";
import { defaultSettings, getClientSettings } from "@/lib/clientSettings";
-import { ProfileSettings, ClientSettings } from "@/types/settings";
-import axios from "axios";
+import { ClientSettings } from "@/types/settings";
import { Dispatch, SetStateAction, useEffect, useState } from "react";
export function useClientSettings(): [
@@ -17,30 +16,3 @@ export function useClientSettings(): [
return [settings, setSettings];
}
-
-export function useProfileSettings(): [
- ProfileSettings,
- Dispatch>
-] {
- const [settings, setSettings] = useState({
- node_address: "",
- username: "",
- display_name: "",
- avatar_url: "",
- });
-
- useEffect(() => {
- async function fetchProfileSettings() {
- try {
- const res = await axios.get("/api/profile");
- setSettings(res.data as ProfileSettings);
- } catch (error) {
- console.error("Failed to fetch profile settings:", error);
- }
- }
-
- fetchProfileSettings();
- }, []);
-
- return [settings, setSettings];
-}
diff --git a/src/types/app.ts b/src/types/app.ts
index 3ddf70b..d6bcd04 100644
--- a/src/types/app.ts
+++ b/src/types/app.ts
@@ -9,8 +9,8 @@ export default interface App {
node: RefObject;
profile: UserProfile | null;
- profiles: StringMap;
- setProfiles: SetState>;
+ profiles: StringMap;
+ setProfiles: SetState>;
messages: Message[];
addMessage: (v: Message) => void;