Fixed settings stuff
This commit is contained in:
@@ -19,7 +19,14 @@ export async function POST(req: NextRequest) {
|
|||||||
{ status: StatusCodes.BAD_REQUEST }
|
{ 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(
|
return NextResponse.json(
|
||||||
{
|
{
|
||||||
message:
|
message:
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ import Link from "next/link";
|
|||||||
import { get, Response } from "@/lib/request";
|
import { get, Response } from "@/lib/request";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import App from "@/types/app";
|
import App from "@/types/app";
|
||||||
|
import { ProfileSettings } from "@/types/settings";
|
||||||
|
|
||||||
export default function AppSidebar({
|
export default function AppSidebar({
|
||||||
children,
|
children,
|
||||||
@@ -201,7 +202,7 @@ export default function AppSidebar({
|
|||||||
</Dialog>
|
</Dialog>
|
||||||
|
|
||||||
<footer className="mt-auto">
|
<footer className="mt-auto">
|
||||||
<SettingsDialog />
|
<SettingsDialog profile={app.profile as ProfileSettings} />
|
||||||
</footer>
|
</footer>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -243,6 +244,7 @@ export default function AppSidebar({
|
|||||||
?.avatar_url || ""
|
?.avatar_url || ""
|
||||||
}
|
}
|
||||||
key={id}
|
key={id}
|
||||||
|
app={app}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</>
|
</>
|
||||||
@@ -256,6 +258,7 @@ export default function AppSidebar({
|
|||||||
id={app.profile?.id || "me"}
|
id={app.profile?.id || "me"}
|
||||||
avatar={app.profile?.avatar_url || ""}
|
avatar={app.profile?.avatar_url || ""}
|
||||||
status="online"
|
status="online"
|
||||||
|
app={app}
|
||||||
settings
|
settings
|
||||||
/>
|
/>
|
||||||
</footer>
|
</footer>
|
||||||
@@ -283,12 +286,14 @@ function DMItem({
|
|||||||
avatar,
|
avatar,
|
||||||
status,
|
status,
|
||||||
settings,
|
settings,
|
||||||
|
app,
|
||||||
}: {
|
}: {
|
||||||
name: string;
|
name: string;
|
||||||
id: string;
|
id: string;
|
||||||
avatar: string;
|
avatar: string;
|
||||||
status: string;
|
status: string;
|
||||||
settings?: boolean;
|
settings?: boolean;
|
||||||
|
app: App;
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<Link
|
<Link
|
||||||
@@ -304,6 +309,7 @@ function DMItem({
|
|||||||
<SettingsDialog
|
<SettingsDialog
|
||||||
className="ml-auto w-7 h-7 p-0 flex items-center justify-center"
|
className="ml-auto w-7 h-7 p-0 flex items-center justify-center"
|
||||||
tab="profile"
|
tab="profile"
|
||||||
|
profile={app.profile as ProfileSettings}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</Link>
|
</Link>
|
||||||
@@ -332,10 +338,12 @@ function ChannelIcon({ kind }: { kind: "text" | "voice" }) {
|
|||||||
|
|
||||||
function getUser(
|
function getUser(
|
||||||
id: string,
|
id: string,
|
||||||
userList: StringMap<UserProfile>,
|
userList: StringMap<UserProfile | null>,
|
||||||
setUserList: React.Dispatch<React.SetStateAction<StringMap<UserProfile>>>
|
setUserList: React.Dispatch<
|
||||||
|
React.SetStateAction<StringMap<UserProfile | null>>
|
||||||
|
>
|
||||||
) {
|
) {
|
||||||
if (userList[id]) return userList[id];
|
if (userList[id] !== undefined) return userList[id];
|
||||||
|
|
||||||
const onResponse = (res: Response<UserProfile>) => {
|
const onResponse = (res: Response<UserProfile>) => {
|
||||||
setUserList((prev) => {
|
setUserList((prev) => {
|
||||||
@@ -346,5 +354,10 @@ function getUser(
|
|||||||
|
|
||||||
get(`/api/profile/?id=${id}`, onResponse)
|
get(`/api/profile/?id=${id}`, onResponse)
|
||||||
?.then(onResponse)
|
?.then(onResponse)
|
||||||
.catch((e) => {});
|
.catch((e) => {
|
||||||
|
setUserList((prev) => {
|
||||||
|
prev[id] = null;
|
||||||
|
return prev;
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useClientSettings } from "@/hooks/use-settings";
|
|
||||||
import { setClientSettings } from "@/lib/clientSettings";
|
import { setClientSettings } from "@/lib/clientSettings";
|
||||||
import SettingSchema from "./SettingSchema";
|
import SettingSchema from "./SettingSchema";
|
||||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
||||||
@@ -11,19 +10,20 @@ import {
|
|||||||
CLIENT_SCHEMA,
|
CLIENT_SCHEMA,
|
||||||
ProfileSettings,
|
ProfileSettings,
|
||||||
} from "@/types/settings";
|
} from "@/types/settings";
|
||||||
import { useParams, useRouter, useSearchParams } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
import { useClientSettings } from "@/hooks/use-settings";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
export default function Settings({
|
export default function Settings({
|
||||||
tab,
|
tab,
|
||||||
profileSettings,
|
profileSettings: ps,
|
||||||
setProfileSettings,
|
|
||||||
}: {
|
}: {
|
||||||
tab?: string;
|
tab?: string;
|
||||||
profileSettings: ProfileSettings;
|
profileSettings: ProfileSettings;
|
||||||
setProfileSettings: React.Dispatch<React.SetStateAction<ProfileSettings>>;
|
|
||||||
}) {
|
}) {
|
||||||
const [settings, setSettings] = useClientSettings();
|
const [settings, setSettings] = useClientSettings();
|
||||||
|
const [profileSettings, setProfileSettings] = useState<ProfileSettings>(ps);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import { Button } from "../ui/button";
|
|||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
DialogDescription,
|
|
||||||
DialogHeader,
|
DialogHeader,
|
||||||
DialogTitle,
|
DialogTitle,
|
||||||
DialogTrigger,
|
DialogTrigger,
|
||||||
@@ -11,18 +10,17 @@ import {
|
|||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import Settings from "./Settings";
|
import Settings from "./Settings";
|
||||||
import { ProfileSettings } from "@/types/settings";
|
import { ProfileSettings } from "@/types/settings";
|
||||||
import { useProfileSettings } from "@/hooks/use-settings";
|
import { useState } from "react";
|
||||||
|
|
||||||
export default function SettingsDialog({
|
export default function SettingsDialog({
|
||||||
className,
|
className,
|
||||||
tab,
|
tab,
|
||||||
|
profile,
|
||||||
}: {
|
}: {
|
||||||
className?: string;
|
className?: string;
|
||||||
tab?: string;
|
tab?: string;
|
||||||
profile?: ProfileSettings;
|
profile: ProfileSettings;
|
||||||
}) {
|
}) {
|
||||||
const [profileSettings, setProfileSettings] = useProfileSettings();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog>
|
<Dialog>
|
||||||
<DialogTrigger asChild>
|
<DialogTrigger asChild>
|
||||||
@@ -41,11 +39,7 @@ export default function SettingsDialog({
|
|||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
|
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
<Settings
|
<Settings tab={tab} profileSettings={profile} />
|
||||||
tab={tab}
|
|
||||||
profileSettings={profileSettings}
|
|
||||||
setProfileSettings={setProfileSettings}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import useUser, { UserProfile } from "./get-user";
|
|||||||
|
|
||||||
export default function useApp(): App {
|
export default function useApp(): App {
|
||||||
const node = useRef<WebSocket | null>(null);
|
const node = useRef<WebSocket | null>(null);
|
||||||
const [profiles, setProfiles] = useState<StringMap<UserProfile>>({});
|
const [profiles, setProfiles] = useState<StringMap<UserProfile | null>>({});
|
||||||
const { messages, addMessage } = useMessages();
|
const { messages, addMessage } = useMessages();
|
||||||
const [sidebarOpen, setSidebarOpen] = useState(true);
|
const [sidebarOpen, setSidebarOpen] = useState(true);
|
||||||
const profile = useUser();
|
const profile = useUser();
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { defaultSettings, getClientSettings } from "@/lib/clientSettings";
|
import { defaultSettings, getClientSettings } from "@/lib/clientSettings";
|
||||||
import { ProfileSettings, ClientSettings } from "@/types/settings";
|
import { ClientSettings } from "@/types/settings";
|
||||||
import axios from "axios";
|
|
||||||
import { Dispatch, SetStateAction, useEffect, useState } from "react";
|
import { Dispatch, SetStateAction, useEffect, useState } from "react";
|
||||||
|
|
||||||
export function useClientSettings(): [
|
export function useClientSettings(): [
|
||||||
@@ -17,30 +16,3 @@ export function useClientSettings(): [
|
|||||||
|
|
||||||
return [settings, setSettings];
|
return [settings, setSettings];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useProfileSettings(): [
|
|
||||||
ProfileSettings,
|
|
||||||
Dispatch<SetStateAction<ProfileSettings>>
|
|
||||||
] {
|
|
||||||
const [settings, setSettings] = useState<ProfileSettings>({
|
|
||||||
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];
|
|
||||||
}
|
|
||||||
|
|||||||
+2
-2
@@ -9,8 +9,8 @@ export default interface App {
|
|||||||
node: RefObject<WebSocket | null>;
|
node: RefObject<WebSocket | null>;
|
||||||
profile: UserProfile | null;
|
profile: UserProfile | null;
|
||||||
|
|
||||||
profiles: StringMap<UserProfile>;
|
profiles: StringMap<UserProfile | null>;
|
||||||
setProfiles: SetState<StringMap<UserProfile>>;
|
setProfiles: SetState<StringMap<UserProfile | null>>;
|
||||||
|
|
||||||
messages: Message[];
|
messages: Message[];
|
||||||
addMessage: (v: Message) => void;
|
addMessage: (v: Message) => void;
|
||||||
|
|||||||
Reference in New Issue
Block a user