mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix share button not working for some users (#5849)

* fix share button

* Revert "fix share button"

This reverts commit 3521c241729dc9bbe3dd7b62fc6e3e61e011cdf9.

* tweak

* Clean up context

---------

Co-authored-by: Eric Bailey <git@esb.lol>

authored by hailey.at

Eric Bailey and committed by
GitHub
2276cb0e 2808f8b7

+48 -27
+20
src/components/Menu/context.tsx
··· 10 10 export const ItemContext = React.createContext<ItemContextType>({ 11 11 disabled: false, 12 12 }) 13 + 14 + export function useMenuContext() { 15 + const context = React.useContext(Context) 16 + 17 + if (!context) { 18 + throw new Error('useMenuContext must be used within a Context.Provider') 19 + } 20 + 21 + return context 22 + } 23 + 24 + export function useMenuItemContext() { 25 + const context = React.useContext(ItemContext) 26 + 27 + if (!context) { 28 + throw new Error('useMenuItemContext must be used within a Context.Provider') 29 + } 30 + 31 + return context 32 + }
+18 -18
src/components/Menu/index.tsx
··· 9 9 import {Button, ButtonText} from '#/components/Button' 10 10 import * as Dialog from '#/components/Dialog' 11 11 import {useInteractionState} from '#/components/hooks/useInteractionState' 12 - import {Context, ItemContext} from '#/components/Menu/context' 12 + import { 13 + Context, 14 + ItemContext, 15 + useMenuContext, 16 + useMenuItemContext, 17 + } from '#/components/Menu/context' 13 18 import { 14 19 ContextType, 15 20 GroupProps, ··· 25 30 useDialogControl as useMenuControl, 26 31 } from '#/components/Dialog' 27 32 28 - export function useMemoControlContext() { 29 - return React.useContext(Context) 30 - } 31 - 32 33 export function Root({ 33 34 children, 34 35 control, ··· 47 48 } 48 49 49 50 export function Trigger({children, label, role = 'button'}: TriggerProps) { 50 - const {control} = React.useContext(Context) 51 + const context = useMenuContext() 51 52 const {state: focused, onIn: onFocus, onOut: onBlur} = useInteractionState() 52 53 const { 53 54 state: pressed, ··· 57 58 58 59 return children({ 59 60 isNative: true, 60 - control, 61 + control: context.control, 61 62 state: { 62 63 hovered: false, 63 64 focused, 64 65 pressed, 65 66 }, 66 67 props: { 67 - onPress: control.open, 68 + onPress: context.control.open, 68 69 onFocus, 69 70 onBlur, 70 71 onPressIn, ··· 82 83 showCancel?: boolean 83 84 style?: StyleProp<ViewStyle> 84 85 }>) { 85 - const context = React.useContext(Context) 86 + const context = useMenuContext() 86 87 const {_} = useLingui() 87 88 88 89 return ( ··· 105 106 106 107 export function Item({children, label, style, onPress, ...rest}: ItemProps) { 107 108 const t = useTheme() 108 - const {control} = React.useContext(Context) 109 + const context = useMenuContext() 109 110 const {state: focused, onIn: onFocus, onOut: onBlur} = useInteractionState() 110 111 const { 111 112 state: pressed, ··· 121 122 onFocus={onFocus} 122 123 onBlur={onBlur} 123 124 onPress={async e => { 124 - await onPress(e) 125 - if (!e.defaultPrevented) { 126 - control?.close() 127 - } 125 + context.control.close(() => { 126 + onPress?.(e) 127 + }) 128 128 }} 129 129 onPressIn={e => { 130 130 onPressIn() ··· 156 156 157 157 export function ItemText({children, style}: ItemTextProps) { 158 158 const t = useTheme() 159 - const {disabled} = React.useContext(ItemContext) 159 + const {disabled} = useMenuItemContext() 160 160 return ( 161 161 <Text 162 162 numberOfLines={1} ··· 177 177 178 178 export function ItemIcon({icon: Comp}: ItemIconProps) { 179 179 const t = useTheme() 180 - const {disabled} = React.useContext(ItemContext) 180 + const {disabled} = useMenuItemContext() 181 181 return ( 182 182 <Comp 183 183 size="lg" ··· 223 223 224 224 function Cancel() { 225 225 const {_} = useLingui() 226 - const {control} = React.useContext(Context) 226 + const context = useMenuContext() 227 227 228 228 return ( 229 229 <Button ··· 231 231 size="small" 232 232 variant="ghost" 233 233 color="secondary" 234 - onPress={() => control.close()}> 234 + onPress={() => context.control.close()}> 235 235 <ButtonText> 236 236 <Trans>Cancel</Trans> 237 237 </ButtonText>
+10 -9
src/components/Menu/index.web.tsx
··· 7 7 import {atoms as a, flatten, useTheme, web} from '#/alf' 8 8 import * as Dialog from '#/components/Dialog' 9 9 import {useInteractionState} from '#/components/hooks/useInteractionState' 10 - import {Context, ItemContext} from '#/components/Menu/context' 10 + import { 11 + Context, 12 + ItemContext, 13 + useMenuContext, 14 + useMenuItemContext, 15 + } from '#/components/Menu/context' 11 16 import { 12 17 ContextType, 13 18 GroupProps, ··· 40 45 ) 41 46 } 42 47 43 - export function useMemoControlContext() { 44 - return React.useContext(Context) 45 - } 46 - 47 48 export function Root({ 48 49 children, 49 50 control, ··· 110 111 RadixTriggerPassThrough.displayName = 'RadixTriggerPassThrough' 111 112 112 113 export function Trigger({children, label, role = 'button'}: TriggerProps) { 113 - const {control} = React.useContext(Context) 114 + const {control} = useMenuContext() 114 115 const { 115 116 state: hovered, 116 117 onIn: onMouseEnter, ··· 203 204 204 205 export function Item({children, label, onPress, ...rest}: ItemProps) { 205 206 const t = useTheme() 206 - const {control} = React.useContext(Context) 207 + const {control} = useMenuContext() 207 208 const { 208 209 state: hovered, 209 210 onIn: onMouseEnter, ··· 262 263 263 264 export function ItemText({children, style}: ItemTextProps) { 264 265 const t = useTheme() 265 - const {disabled} = React.useContext(ItemContext) 266 + const {disabled} = useMenuItemContext() 266 267 return ( 267 268 <Text 268 269 style={[ ··· 279 280 280 281 export function ItemIcon({icon: Comp, position = 'left'}: ItemIconProps) { 281 282 const t = useTheme() 282 - const {disabled} = React.useContext(ItemContext) 283 + const {disabled} = useMenuItemContext() 283 284 return ( 284 285 <View 285 286 style={[