-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: direct message sending feature
- Loading branch information
Showing
13 changed files
with
128 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/app/create_private_message/[userid]/PrivateMessageEditor.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
"use client"; | ||
|
||
import { PersonView } from "lemmy-js-client"; | ||
import { SubmitButton } from "@/app/(ui)/button/SubmitButton"; | ||
import { ButtonLink } from "@/app/(ui)/button/ButtonLink"; | ||
import classNames from "classnames"; | ||
import { TextArea } from "@/app/(ui)/form/TextArea"; | ||
import { createPrivateMessageAction } from "@/app/create_private_message/privateMessageActions"; | ||
import { UserLink } from "@/app/u/UserLink"; | ||
|
||
export const PrivateMessageEditor = (props: { | ||
readonly recipientPersonView: PersonView; | ||
}) => { | ||
return ( | ||
<form | ||
action={createPrivateMessageAction.bind( | ||
null, | ||
props.recipientPersonView.person.id, | ||
)} | ||
className={"flex max-w-[880px] flex-col gap-4"} | ||
> | ||
<div> | ||
<label className={"block font-semibold"} htmlFor={"title"}> | ||
{"Recipient"} | ||
</label> | ||
<UserLink person={props.recipientPersonView.person} /> | ||
</div> | ||
|
||
<div> | ||
<label className={"block font-semibold"} htmlFor={"content"}> | ||
{"Message"} | ||
</label> | ||
|
||
<TextArea | ||
className={classNames("mt-2 min-h-32")} | ||
id={"content"} | ||
name={"content"} | ||
/> | ||
</div> | ||
<input | ||
autoComplete={"false"} | ||
className={"hidden"} | ||
id={"honey"} | ||
name={"honey"} | ||
type={"text"} | ||
/> | ||
|
||
<div className={"mt-2 flex items-center justify-end gap-2"}> | ||
<ButtonLink href={`/inbox`}>{"Cancel"}</ButtonLink> | ||
<SubmitButton color={"primary"}>{"Send"}</SubmitButton> | ||
</div> | ||
</form> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { apiClient } from "@/app/apiClient"; | ||
import { loginPageWithRedirectAction } from "@/app/login/authActions"; | ||
import { PrivateMessageEditor } from "@/app/create_private_message/[userid]/PrivateMessageEditor"; | ||
|
||
const CreateDirectMessagePage = async (props: { | ||
readonly params: { userid: number }; | ||
}) => { | ||
const { my_user: loggedInUser } = await apiClient.getSite(); | ||
if (!loggedInUser) { | ||
await loginPageWithRedirectAction( | ||
`/create_private_message/${props.params.userid}`, | ||
true, | ||
); | ||
} | ||
|
||
const { person_view: personView } = await apiClient.getPersonDetails({ | ||
person_id: props.params.userid, | ||
}); | ||
|
||
return ( | ||
<div className={"m-2 lg:m-4"}> | ||
<h1 className={"mb-4 text-xl font-bold"}> | ||
{"Composing direct message..."} | ||
</h1> | ||
<PrivateMessageEditor recipientPersonView={personView} /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default CreateDirectMessagePage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
"use server"; | ||
|
||
import { apiClient } from "@/app/apiClient"; | ||
|
||
export const createPrivateMessageAction = async ( | ||
recipientPersonId: number, | ||
form: FormData, | ||
) => { | ||
await apiClient.createPrivateMessage({ | ||
content: form.get("content")?.toString()!, | ||
recipient_id: recipientPersonId, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters