diff --git a/.env b/.env index 5352c86..cdccac1 100644 --- a/.env +++ b/.env @@ -1,5 +1,5 @@ NEXT_PUBLIC_METADATA_URL=https://paradigmthreat.net -NEXT_PUBLIC_API=https://api.paradigmthreat.com +NEXT_PUBLIC_API=https://api.paradigmthreat.net NEXT_PUBLIC_ASSET_PATH=app NEXT_PUBLIC_ASSET_BUILD=dist NEXT_PUBLIC_ASSET_NAV_IGNORE_FILE=.navignore diff --git a/components/ChatRoom/ChatRoom.js b/components/ChatRoom/ChatRoom.js index d2241cc..483ede9 100644 --- a/components/ChatRoom/ChatRoom.js +++ b/components/ChatRoom/ChatRoom.js @@ -5,6 +5,7 @@ import Markdown from 'markdown-to-jsx' import styles from './ChatRoom.module.scss' import { ErrorBoundary } from '@client' + const API_URL = process.env.NEXT_PUBLIC_API export default function ChatRoom ({ channel, title, className }) { @@ -22,9 +23,9 @@ export default function ChatRoom ({ channel, title, className }) { setChannelInfo(channelInfo) } }).catch(error => { - console.error(error.message) - setError(error.message) - }) + console.error(error) + setError(error.message) + }) }, [channel]) async function onKeyDown (event) { @@ -36,50 +37,57 @@ export default function ChatRoom ({ channel, title, className }) { async function onSubmit (event) { event.preventDefault() + try { - const formElm = event.target.form || event.target - const formData = new FormData(formElm) - const formDataObject = Object.fromEntries(formData.entries()) - if (!formDataObject.username) { formDataObject.username = 'guest' } - formElm.elements.message.value = '' - formElm.elements.message.disabled = true - const response = await fetch(`/api/chat/channel/${channel}/createGuestPost`, { - headers: { - 'Content-Type': 'application/json', - Accept: 'application/json' - }, - method: 'POST', - body: JSON.stringify(formDataObject) - }) + const formElm = event.target.form || event.target + const formData = new FormData(formElm) + const formDataObject = Object.fromEntries(formData.entries()) + if (!formDataObject.username) { formDataObject.username = 'guest' } + formElm.elements.message.value = '' + formElm.elements.message.disabled = true + const response = await fetch(`${API_URL}/api/chat/channel/${channel}/createGuestPost`, { + headers: { + 'Content-Type': 'application/json', + Accept: 'application/json' + }, + method: 'POST', + body: JSON.stringify(formDataObject) + }) - const { message, username } = await response.json() - setChannelInfo({ - ...channelInfo, - posts: [ - ...channelInfo.posts, - { - username, - message - } - ] - }) - formElm.elements.message.disabled = false + const { message, username } = await response.json() + setChannelInfo({ + ...channelInfo, + posts: [ + ...channelInfo.posts, + { + username, + message + } + ] + }) + formElm.elements.message.disabled = false + } catch (error) { + const errorMessage = `Error submitting message: ${error.message}` + console.error(error) + setError(errorMessage) + } } + // console.log('error', error) return (
{title || channel}
- {channelInfo?.posts?.map(({ username, message }, index) => ( -
+ {channelInfo?.posts?.map(({ username, message, create_at }, index) => ( +
{username} {message}
@@ -87,32 +95,32 @@ export default function ChatRoom ({ channel, title, className }) { {error &&
Could not load chatroom: {error}
}
-
+
- Open {title || channel} in new window + Visit {title || channel} in new window