-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
swipeable comments plus more refactoring
- Loading branch information
Showing
17 changed files
with
438 additions
and
143 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
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,9 @@ | ||
import { SwipeableActionParams } from '@components/Common/SwipeableRow/actions/swipeableActions'; | ||
|
||
export const customOption = (params: SwipeableActionParams): void => { | ||
const { custom } = params; | ||
|
||
if (custom == null) return; | ||
|
||
custom(params); | ||
}; |
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
77 changes: 77 additions & 0 deletions
77
src/components/Common/SwipeableRow/hooks/useCommentSwipeOptions.ts
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,77 @@ | ||
import { useTheme } from 'tamagui'; | ||
import { useMemo } from 'react'; | ||
import { | ||
useCommentGesturesFirstLeft, | ||
useCommentGesturesFirstRight, | ||
useCommentGesturesSecondLeft, | ||
useCommentGesturesSecondRight, | ||
} from '@src/state/settings/settingsStore'; | ||
import { commentSwipeableActions } from '@components/Common/SwipeableRow/actions'; | ||
import { IPostGestureOption } from '@src/types'; | ||
import { | ||
ISwipeableActions, | ||
ISwipeableColors, | ||
ISwipeableOptions, | ||
} from '@components/Common/SwipeableRow/types'; | ||
|
||
export const useCommentSwipeOptions = ( | ||
side: 'right' | 'left', | ||
): ISwipeableOptions => { | ||
const theme = useTheme(); | ||
|
||
const firstLeft = useCommentGesturesFirstLeft(); | ||
const firstRight = useCommentGesturesFirstRight(); | ||
const secondLeft = useCommentGesturesSecondLeft(); | ||
const secondRight = useCommentGesturesSecondRight(); | ||
|
||
const swipeColorOptions = useMemo<Record<IPostGestureOption, string>>( | ||
() => ({ | ||
upvote: theme.upvote.val, | ||
downvote: theme.downvote.val, | ||
save: theme.bookmark.val, | ||
hide: theme.warn.val, | ||
reply: theme.accent.val, | ||
collapse: theme.warn.val, | ||
}), | ||
[theme], | ||
); | ||
|
||
const swipeActions = useMemo<ISwipeableActions>(() => { | ||
const first = side === 'left' ? firstLeft : firstRight; | ||
const second = side === 'left' ? secondLeft : secondRight; | ||
|
||
return { | ||
first: first !== 'none' ? commentSwipeableActions[first] : undefined, | ||
second: second !== 'none' ? commentSwipeableActions[second] : undefined, | ||
}; | ||
}, [firstLeft, firstRight, secondLeft, secondRight]); | ||
|
||
const swipeColors = useMemo<ISwipeableColors>(() => { | ||
const first = side === 'left' ? firstLeft : firstRight; | ||
const second = side === 'left' ? secondLeft : secondRight; | ||
|
||
return { | ||
first: | ||
first !== 'none' ? swipeColorOptions[first] ?? '$accent' : '$accent', | ||
second: | ||
second !== 'none' ? swipeColorOptions[second] ?? undefined : undefined, | ||
}; | ||
}, [firstLeft, firstRight, secondLeft, secondRight, swipeColorOptions]); | ||
|
||
// @ts-expect-error TODO Fix this | ||
const swipeIcons = useMemo<ISwipeableIcons>(() => { | ||
const first = side === 'left' ? firstLeft : firstRight; | ||
const second = side === 'left' ? secondLeft : secondRight; | ||
|
||
return { | ||
first: first !== 'none' ? first : undefined, | ||
second: second !== 'none' ? second : undefined, | ||
}; | ||
}, [firstLeft, firstRight, secondLeft, secondRight]); | ||
|
||
return { | ||
actions: swipeActions, | ||
colors: swipeColors, | ||
icons: swipeIcons, | ||
}; | ||
}; |
Oops, something went wrong.