-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: basic user and message context menus (just so we have them)
- Loading branch information
Showing
6 changed files
with
164 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { styled } from "@revolt/ui"; | ||
|
||
export const ContextMenu = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
background: ${(props) => props.theme!.colours.accent}; | ||
`; | ||
|
||
export const ContextMenuDivider = styled.div``; | ||
|
||
export const ContextMenuButton = styled.a` | ||
margin: 2px; | ||
display: block; | ||
background: red; | ||
`; |
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 @@ | ||
import { Message } from "revolt.js"; | ||
|
||
import { useUser } from "@revolt/client"; | ||
import { state } from "@revolt/state"; | ||
|
||
import { ContextMenu, ContextMenuButton } from "./ContextMenu"; | ||
|
||
/** | ||
* | ||
* @param props | ||
* @returns | ||
*/ | ||
export function MessageContextMenu(props: { message: Message }) { | ||
const user = useUser(); | ||
|
||
return ( | ||
<ContextMenu> | ||
my context menu.jpg{" "} | ||
<ContextMenuButton | ||
onClick={() => { | ||
state.draft.addReply(props.message, user()!.id); | ||
}} | ||
> | ||
Reply | ||
</ContextMenuButton> | ||
<ContextMenuButton>Mark as unread</ContextMenuButton> | ||
<ContextMenuButton | ||
onClick={() => { | ||
navigator.clipboard.writeText(props.message.content); | ||
}} | ||
> | ||
Copy text | ||
</ContextMenuButton> | ||
<ContextMenuButton>Report message</ContextMenuButton> | ||
<ContextMenuButton | ||
onClick={() => { | ||
props.message.delete(); | ||
}} | ||
> | ||
Delete message | ||
</ContextMenuButton> | ||
<ContextMenuButton | ||
onClick={() => | ||
window.open( | ||
`https://admin.revolt.chat/panel/inspect/message/${props.message.id}`, | ||
"_blank" | ||
) | ||
} | ||
> | ||
Admin Panel | ||
</ContextMenuButton> | ||
</ContextMenu> | ||
); | ||
} |
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,68 @@ | ||
import { JSX, Show } from "solid-js"; | ||
|
||
import { ServerMember, User } from "revolt.js"; | ||
|
||
import { ContextMenu, ContextMenuButton } from "./ContextMenu"; | ||
|
||
/** | ||
* | ||
* @param props | ||
* @returns | ||
*/ | ||
export function UserContextMenu(props: { user?: User; member?: ServerMember }) { | ||
// TODO: if we take serverId instead, we could dynamically fetch server member here | ||
// same for the floating menu I guess? | ||
|
||
return ( | ||
<ContextMenu> | ||
user context menu.jpg{" "} | ||
<Show when={props.member}> | ||
<ContextMenuButton | ||
onClick={() => prompt("u sure?") && props.member!.kick()} | ||
> | ||
Kick Member | ||
</ContextMenuButton> | ||
<ContextMenuButton | ||
onClick={() => | ||
prompt("u sure?") && props.member!.ban({ reason: "die" }) | ||
} | ||
> | ||
Ban Member (reason = "die") | ||
</ContextMenuButton> | ||
</Show> | ||
<ContextMenuButton | ||
onClick={() => | ||
window.open( | ||
`https://admin.revolt.chat/panel/inspect/user/${props.user?.id}`, | ||
"_blank" | ||
) | ||
} | ||
> | ||
Admin Panel | ||
</ContextMenuButton> | ||
</ContextMenu> | ||
); | ||
} | ||
|
||
/** | ||
* Provide floating user menus on this element | ||
* @param user User | ||
* @param member Server Member | ||
*/ | ||
export function floatingUserMenus( | ||
user: User, | ||
member?: ServerMember | ||
): JSX.Directives["floating"] & object { | ||
return { | ||
userCard: { | ||
user, | ||
member, | ||
}, | ||
/** | ||
* Build user context menu | ||
*/ | ||
contextMenu() { | ||
return <UserContextMenu user={user} member={member} />; | ||
}, | ||
}; | ||
} |
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