-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[web] Introduce barebones
EditThreadAvatarMenu
Summary: Similar to `EditUserAvatarMenu`, but for threads. This diff only introduces the "Reset to default" functionality. Next diff will add image avatar support. The diff after that will add emoji support. Test Plan: 1. Set thread avatar 2. Press "Reset to default" button and observe that thread avatar is unset in DB Reviewers: ashoat, ginsu Reviewed By: ginsu Subscribers: tomek Differential Revision: https://phab.comm.dev/D8840
- Loading branch information
1 parent
b64ec4c
commit 8ef4521
Showing
5 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
File renamed without changes.
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,57 @@ | ||
// @flow | ||
|
||
import invariant from 'invariant'; | ||
import * as React from 'react'; | ||
|
||
import { EditThreadAvatarContext } from 'lib/components/base-edit-thread-avatar-provider.react.js'; | ||
import SWMansionIcon from 'lib/components/SWMansionIcon.react.js'; | ||
import type { RawThreadInfo, ThreadInfo } from 'lib/types/thread-types.js'; | ||
|
||
import css from './edit-avatar-menu.css'; | ||
import MenuItem from '../components/menu-item.react.js'; | ||
import Menu from '../components/menu.react.js'; | ||
|
||
const editIcon = ( | ||
<div className={css.editAvatarBadge}> | ||
<SWMansionIcon icon="edit-2" size={20} /> | ||
</div> | ||
); | ||
|
||
type Props = { | ||
+threadInfo: RawThreadInfo | ThreadInfo, | ||
}; | ||
function EditThreadAvatarMenu(props: Props): React.Node { | ||
const { threadInfo } = props; | ||
|
||
const editThreadAvatarContext = React.useContext(EditThreadAvatarContext); | ||
invariant(editThreadAvatarContext, 'editThreadAvatarContext should be set'); | ||
|
||
const { baseSetThreadAvatar } = editThreadAvatarContext; | ||
|
||
const removeThreadAvatar = React.useCallback( | ||
() => baseSetThreadAvatar(threadInfo.id, { type: 'remove' }), | ||
[baseSetThreadAvatar, threadInfo.id], | ||
); | ||
|
||
const removeMenuItem = React.useMemo( | ||
() => ( | ||
<MenuItem | ||
key="remove" | ||
text="Reset to default" | ||
icon="trash-2" | ||
onClick={removeThreadAvatar} | ||
/> | ||
), | ||
[removeThreadAvatar], | ||
); | ||
|
||
const menuItems = React.useMemo(() => [removeMenuItem], [removeMenuItem]); | ||
|
||
return ( | ||
<div> | ||
<Menu icon={editIcon}>{menuItems}</Menu> | ||
</div> | ||
); | ||
} | ||
|
||
export default EditThreadAvatarMenu; |
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