Skip to content

Commit

Permalink
Add basic conversation creation function
Browse files Browse the repository at this point in the history
  • Loading branch information
KingRainbow44 committed Sep 6, 2023
1 parent d8c5e56 commit 02d37d4
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/ui/pages/ChatPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,28 @@ class ChatPage extends React.Component<IProps, IState> {
}
}

/**
* Creates a new conversation.
*
* @param name The name of the conversation.
* @private
*/
private async createConversation(name: string = "Cool Conversation"): Promise<void> {
// Get the selected channel.
const selected = this.state.selectedChannel;
if (!selected) throw new Error("No channel selected.");

// Get the credentials.
const { token } = getCredentials();
// Create the conversation.
const body = JSON.stringify({
name, channelId: selected.id
});
await fetch(newCall(`conversation`), {
method: "POST", body, headers: { Authorization: token }
});
}

/**
* Sets the width of the text input box.
*/
Expand Down Expand Up @@ -353,7 +375,8 @@ class ChatPage extends React.Component<IProps, IState> {
<CreateChannel />

<ContextMenu id={"channelContext"} options={[
{ name: "Delete Channel", action: this.deleteSelectedChannel.bind(this) }
{ name: "Delete Channel", action: this.deleteSelectedChannel.bind(this) },
{ name: "New Conversation", action: this.createConversation.bind(this) }
]} />

<div className={"ChatPage"}>
Expand Down

0 comments on commit 02d37d4

Please sign in to comment.