| 29 | }; |
| 30 | |
| 31 | export default function useFeedContextMenu(): FeedContextMenu { |
| 32 | const [postMenuLocation, setPostMenuLocation] = |
| 33 | useState<PostLocation | null>(); |
| 34 | const postMenuIndex = postMenuLocation?.index; |
| 35 | |
| 36 | const onMenuClick = ( |
| 37 | e: React.MouseEvent, |
| 38 | index: number, |
| 39 | row: number, |
| 40 | column: number, |
| 41 | ) => { |
| 42 | if (postMenuIndex === index) { |
| 43 | setPostMenuLocation(null); |
| 44 | return; |
| 45 | } |
| 46 | setPostMenuLocation({ index, row, column }); |
| 47 | }; |
| 48 | |
| 49 | const onShareMenuClick = ( |
| 50 | e: React.MouseEvent, |
| 51 | _post: Post, |
| 52 | index: number, |
| 53 | row: number, |
| 54 | column: number, |
| 55 | ) => { |
| 56 | if (postMenuIndex === index) { |
| 57 | setPostMenuLocation(null); |
| 58 | return; |
| 59 | } |
| 60 | setPostMenuLocation({ index, row, column }); |
| 61 | }; |
| 62 | |
| 63 | return { |
| 64 | onMenuClick, |
| 65 | onShareMenuClick, |
| 66 | postMenuIndex, |
| 67 | postMenuLocation, |
| 68 | setPostMenuIndex: setPostMenuLocation, |
| 69 | }; |
| 70 | } |