diff --git a/.env.development b/.env.development index 8ba2b75..e8ffc9a 100644 --- a/.env.development +++ b/.env.development @@ -1,6 +1,5 @@ API_VERSION=1 -API_URL=http://localhost:3002/api -GATEWAY_URL=http://localhost:3002 +GATEWAY_URL=http://localhost:4000 AUTH_URL=http://localhost:3003 CDN_URL=http://localhost:3004 MEDIA_PROXY_URL=http://localhost:3005 \ No newline at end of file diff --git a/src/app/channels/[channelId]/page.tsx b/src/app/channels/[channelId]/page.tsx index c0621ea..cfaffd1 100644 --- a/src/app/channels/[channelId]/page.tsx +++ b/src/app/channels/[channelId]/page.tsx @@ -7,9 +7,9 @@ import { useDispatch } from 'react-redux'; export default function SelectedChannelPage({ params -}: { +}: Readonly<{ params: { channelId: string }; -}) { +}>) { const { channelId } = params; const dispatch = useDispatch(); diff --git a/src/client/links.ts b/src/client/links.ts index 6e52c23..31d7ebf 100644 --- a/src/client/links.ts +++ b/src/client/links.ts @@ -1,6 +1,6 @@ export class ClientLinks { - api = process.env['API_URL'] as string; - cdn = process.env['CDN_URL'] as string; + api = process.env['API_URL']; + cdn = process.env['CDN_URL']; gateway = process.env['GATEWAY_URL'] ?? ('https://chat-backend.tnfangel.com' as string); - proxy = process.env['MEDIA_PROXY_URL'] as string; + proxy = process.env['MEDIA_PROXY_URL']; } diff --git a/src/components/channel/InputArea.tsx b/src/components/channel/InputArea.tsx index 6948204..ac56265 100644 --- a/src/components/channel/InputArea.tsx +++ b/src/components/channel/InputArea.tsx @@ -131,36 +131,37 @@ export default function InputArea({ channel }: InputBoxProps) { client.sentMessagesIds.push(tempMessageId); - await ky - .post(`${client.links.api}/channels/${channel?.id}/messages`, { - json: { content: content, nonce: tempMessageId } - }) - .json<{ id: string }>() - .then((result) => { - dispatch( - modifyMessage({ - channelId: rawMessage.channelId, - messageId: rawMessage.id, - newMessage: normalizeMessage({ - ...rawMessage, - mode: MessageModes.Sent, - id: result.id + if (client.links.api) + await ky + .post(`${client.links.api}/channels/${channel?.id}/messages`, { + json: { content: content, nonce: tempMessageId } + }) + .json<{ id: string }>() + .then((result) => { + dispatch( + modifyMessage({ + channelId: rawMessage.channelId, + messageId: rawMessage.id, + newMessage: normalizeMessage({ + ...rawMessage, + mode: MessageModes.Sent, + id: result.id + }) }) - }) - ); - }) - .catch(() => { - dispatch( - modifyMessage({ - channelId: rawMessage.channelId, - messageId: rawMessage.id, - newMessage: normalizeMessage({ - ...rawMessage, - mode: MessageModes.Blocked + ); + }) + .catch(() => { + dispatch( + modifyMessage({ + channelId: rawMessage.channelId, + messageId: rawMessage.id, + newMessage: normalizeMessage({ + ...rawMessage, + mode: MessageModes.Blocked + }) }) - }) - ); - }); + ); + }); } } diff --git a/src/components/screens/GuildScreen.tsx b/src/components/screens/GuildScreen.tsx index d8b250e..9c7616c 100644 --- a/src/components/screens/GuildScreen.tsx +++ b/src/components/screens/GuildScreen.tsx @@ -1,7 +1,7 @@ 'use client'; import useThemeColors from '@/hooks/useThemeColors'; import type { RootState } from '@/store'; -import { Center, Text, Flex, Heading, Stack } from '@chakra-ui/react'; +import { Center, Flex, Heading, Stack, Text } from '@chakra-ui/react'; import { useRouter } from 'next/navigation'; import { useRef } from 'react'; import GuildSidebar from '../layout/GuildSidebar'; @@ -49,7 +49,9 @@ export default function GuildScreen() { >
- Welcome to {guild.name} + + Welcome to {guild.name} + Select a channel to get started.
diff --git a/src/hooks/useChannel.ts b/src/hooks/useChannel.ts index a7bfb8e..96f3f4a 100644 --- a/src/hooks/useChannel.ts +++ b/src/hooks/useChannel.ts @@ -3,7 +3,9 @@ import type { IRawChannel } from '@/types/interfaces/Channel'; import useSWRImmutable from 'swr/immutable'; export default function useChannel(channelId: string) { - const { data, isLoading, error } = useSWRImmutable(`${client.links.api}/channels/${channelId}`); + const { data, isLoading, error } = useSWRImmutable( + client.links.api ? `${client.links.api}/channels/${channelId}` : undefined + ); return { data, isLoading, error }; } diff --git a/src/hooks/useMessage.ts b/src/hooks/useMessage.ts index f025fa8..5678a41 100644 --- a/src/hooks/useMessage.ts +++ b/src/hooks/useMessage.ts @@ -4,7 +4,7 @@ import useSWRImmutable from 'swr/immutable'; export default function useChannelMessage(channelId: string, messageId: string) { const { data, isLoading, error } = useSWRImmutable( - `${client.links.api}/channels/${channelId}/messages/${messageId}` + client.links.api ? `${client.links.api}/channels/${channelId}/messages/${messageId}` : undefined ); return { data, isLoading, error }; diff --git a/src/hooks/useMessages.ts b/src/hooks/useMessages.ts index 5a0ac7a..74261c0 100644 --- a/src/hooks/useMessages.ts +++ b/src/hooks/useMessages.ts @@ -3,12 +3,16 @@ import type { IRawMessage } from '@/types/interfaces/Message'; import useSWRImmutable from 'swr/immutable'; export default function useChannelMessages(channelId: string, before?: string | null, after?: string | null) { - const url = new URL(`${client.links.api}/channels/${channelId}/messages`); + let url; - if (before) url.searchParams.set('before', before); - if (after) url.searchParams.set('after', after); + if (client.links.api) { + url = new URL(`${client.links.api}/channels/${channelId}/messages`); - const { data, isLoading, error } = useSWRImmutable(url.toString()); + if (before) url.searchParams.set('before', before); + if (after) url.searchParams.set('after', after); + } + + const { data, isLoading, error } = useSWRImmutable(url?.toString()); return { data, isLoading, error }; } diff --git a/src/hooks/useUser.ts b/src/hooks/useUser.ts index 13b8e2b..e264f42 100644 --- a/src/hooks/useUser.ts +++ b/src/hooks/useUser.ts @@ -3,7 +3,9 @@ import type { IRawUser } from '@/types/interfaces/User'; import useSWRImmutable from 'swr/immutable'; export default function useUser(userId: string) { - const { data, isLoading, error } = useSWRImmutable(`${client.links.api}/api/users/${userId}`); + const { data, isLoading, error } = useSWRImmutable( + client.links.api ? `${client.links.api}/api/users/${userId}` : undefined + ); return { data, isLoading, error }; }