Create codemod for addressing ESLint warnings (#10032)
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import {View} from 'react-native'
|
||||
import type React from 'react'
|
||||
|
||||
import {MAX_ALT_TEXT} from '#/lib/constants'
|
||||
import {CharProgress} from '#/view/com/composer/char-progress/CharProgress'
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import React, {
|
||||
import {
|
||||
Fragment,
|
||||
memo,
|
||||
useCallback,
|
||||
useEffect,
|
||||
useImperativeHandle,
|
||||
@@ -299,7 +301,7 @@ export const ComposePost = ({
|
||||
[activePost.id],
|
||||
)
|
||||
|
||||
const selectVideo = React.useCallback(
|
||||
const selectVideo = useCallback(
|
||||
(postId: string, asset: ImagePickerAsset) => {
|
||||
const abortController = new AbortController()
|
||||
composerDispatch({
|
||||
@@ -485,7 +487,7 @@ export const ComposePost = ({
|
||||
[_, agent, currentDid, composerDispatch],
|
||||
)
|
||||
|
||||
const handleSelectDraft = React.useCallback(
|
||||
const handleSelectDraft = useCallback(
|
||||
async (draftSummary: DraftSummary) => {
|
||||
logger.debug('loading draft for editing', {
|
||||
draftId: draftSummary.id,
|
||||
@@ -553,7 +555,7 @@ export const ComposePost = ({
|
||||
revokeAllMediaUrls()
|
||||
}, [closeComposer, queryClient])
|
||||
|
||||
const getDraftSaveError = React.useCallback(
|
||||
const getDraftSaveError = useCallback(
|
||||
(e: unknown): string => {
|
||||
if (e instanceof AppBskyDraftCreateDraft.DraftLimitReachedError) {
|
||||
return _(msg`You've reached the maximum number of drafts`)
|
||||
@@ -563,7 +565,7 @@ export const ComposePost = ({
|
||||
[_],
|
||||
)
|
||||
|
||||
const validateDraftTextOrError = React.useCallback((): boolean => {
|
||||
const validateDraftTextOrError = useCallback((): boolean => {
|
||||
const tooLong = composerState.thread.posts.some(
|
||||
post => post.richtext.graphemeLength > MAX_DRAFT_GRAPHEME_LENGTH,
|
||||
)
|
||||
@@ -578,7 +580,7 @@ export const ComposePost = ({
|
||||
return true
|
||||
}, [composerState.thread.posts, _])
|
||||
|
||||
const handleSaveDraft = React.useCallback(async () => {
|
||||
const handleSaveDraft = useCallback(async () => {
|
||||
setError('')
|
||||
if (!validateDraftTextOrError()) {
|
||||
return
|
||||
@@ -621,7 +623,7 @@ export const ComposePost = ({
|
||||
])
|
||||
|
||||
// Save without closing - for use by DraftsButton
|
||||
const saveCurrentDraft = React.useCallback(async (): Promise<{
|
||||
const saveCurrentDraft = useCallback(async (): Promise<{
|
||||
success: boolean
|
||||
}> => {
|
||||
setError('')
|
||||
@@ -648,7 +650,7 @@ export const ComposePost = ({
|
||||
])
|
||||
|
||||
// Handle discard action - fires metric and closes composer
|
||||
const handleDiscard = React.useCallback(() => {
|
||||
const handleDiscard = useCallback(() => {
|
||||
const posts = thread.posts
|
||||
const hasContent = posts.some(
|
||||
post =>
|
||||
@@ -665,7 +667,7 @@ export const ComposePost = ({
|
||||
}, [thread.posts, ax, onClose])
|
||||
|
||||
// Check if composer is empty (no content to save)
|
||||
const isComposerEmpty = React.useMemo(() => {
|
||||
const isComposerEmpty = useMemo(() => {
|
||||
// Has multiple posts means it's not empty
|
||||
if (thread.posts.length > 1) return false
|
||||
|
||||
@@ -683,7 +685,7 @@ export const ComposePost = ({
|
||||
}, [thread.posts])
|
||||
|
||||
// Clear the composer (discard current content)
|
||||
const handleClearComposer = React.useCallback(() => {
|
||||
const handleClearComposer = useCallback(() => {
|
||||
composerDispatch({
|
||||
type: 'clear',
|
||||
initInteractionSettings: preferences?.postInteractionSettings,
|
||||
@@ -794,7 +796,7 @@ export const ComposePost = ({
|
||||
),
|
||||
)
|
||||
|
||||
const onPressPublish = React.useCallback(async () => {
|
||||
const onPressPublish = useCallback(async () => {
|
||||
if (isPublishing) {
|
||||
return
|
||||
}
|
||||
@@ -1015,7 +1017,7 @@ export const ComposePost = ({
|
||||
onPressPublish()
|
||||
})
|
||||
|
||||
React.useEffect(() => {
|
||||
useEffect(() => {
|
||||
if (publishOnUpload) {
|
||||
let erroredVideos = 0
|
||||
let uploadingVideos = 0
|
||||
@@ -1181,7 +1183,7 @@ export const ComposePost = ({
|
||||
onLayout={onScrollViewLayout}>
|
||||
{replyTo ? <ComposerReplyTo replyTo={replyTo} /> : undefined}
|
||||
{thread.posts.map((post, index) => (
|
||||
<React.Fragment key={post.id + (composerState.draftId ?? '')}>
|
||||
<Fragment key={post.id + (composerState.draftId ?? '')}>
|
||||
<ComposerPost
|
||||
post={post}
|
||||
dispatch={composerDispatch}
|
||||
@@ -1201,7 +1203,7 @@ export const ComposePost = ({
|
||||
{IS_WEBFooterSticky && post.id === activePost.id && (
|
||||
<View style={styles.stickyFooterWeb}>{footer}</View>
|
||||
)}
|
||||
</React.Fragment>
|
||||
</Fragment>
|
||||
))}
|
||||
</Animated.ScrollView>
|
||||
{!IS_WEBFooterSticky && footer}
|
||||
@@ -1273,7 +1275,7 @@ export const ComposePost = ({
|
||||
)
|
||||
}
|
||||
|
||||
let ComposerPost = React.memo(function ComposerPost({
|
||||
let ComposerPost = memo(function ComposerPost({
|
||||
post,
|
||||
dispatch,
|
||||
textInput,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import {View} from 'react-native'
|
||||
import {KeyboardStickyView} from 'react-native-keyboard-controller'
|
||||
import {useSafeAreaInsets} from 'react-native-safe-area-context'
|
||||
import type React from 'react'
|
||||
|
||||
import {atoms as a, useTheme} from '#/alf'
|
||||
import {IS_WEB} from '#/env'
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, {useState} from 'react'
|
||||
import {memo, useMemo, useState} from 'react'
|
||||
import {
|
||||
findNodeHandle,
|
||||
type ImageStyle,
|
||||
@@ -37,7 +37,7 @@ interface GalleryProps {
|
||||
}
|
||||
|
||||
export let Gallery = (props: GalleryProps): React.ReactNode => {
|
||||
const [containerInfo, setContainerInfo] = React.useState<Dimensions>()
|
||||
const [containerInfo, setContainerInfo] = useState<Dimensions>()
|
||||
|
||||
const onLayout = (evt: LayoutChangeEvent) => {
|
||||
const {width, height} = evt.nativeEvent.layout
|
||||
@@ -55,7 +55,7 @@ export let Gallery = (props: GalleryProps): React.ReactNode => {
|
||||
</View>
|
||||
)
|
||||
}
|
||||
Gallery = React.memo(Gallery)
|
||||
Gallery = memo(Gallery)
|
||||
|
||||
interface GalleryInnerProps extends GalleryProps {
|
||||
containerInfo: Dimensions
|
||||
@@ -64,39 +64,38 @@ interface GalleryInnerProps extends GalleryProps {
|
||||
const GalleryInner = ({images, containerInfo, dispatch}: GalleryInnerProps) => {
|
||||
const {isMobile} = useWebMediaQueries()
|
||||
|
||||
const {altTextControlStyle, imageControlsStyle, imageStyle} =
|
||||
React.useMemo(() => {
|
||||
const side =
|
||||
images.length === 1
|
||||
? 250
|
||||
: (containerInfo.width - IMAGE_GAP * (images.length - 1)) /
|
||||
images.length
|
||||
const {altTextControlStyle, imageControlsStyle, imageStyle} = useMemo(() => {
|
||||
const side =
|
||||
images.length === 1
|
||||
? 250
|
||||
: (containerInfo.width - IMAGE_GAP * (images.length - 1)) /
|
||||
images.length
|
||||
|
||||
const isOverflow = isMobile && images.length > 2
|
||||
const isOverflow = isMobile && images.length > 2
|
||||
|
||||
return {
|
||||
altTextControlStyle: isOverflow
|
||||
? {left: 4, bottom: 4}
|
||||
return {
|
||||
altTextControlStyle: isOverflow
|
||||
? {left: 4, bottom: 4}
|
||||
: !isMobile && images.length < 3
|
||||
? {left: 8, top: 8}
|
||||
: {left: 4, top: 4},
|
||||
imageControlsStyle: {
|
||||
display: 'flex' as const,
|
||||
flexDirection: 'row' as const,
|
||||
position: 'absolute' as const,
|
||||
...(isOverflow
|
||||
? {top: 4, right: 4, gap: 4}
|
||||
: !isMobile && images.length < 3
|
||||
? {left: 8, top: 8}
|
||||
: {left: 4, top: 4},
|
||||
imageControlsStyle: {
|
||||
display: 'flex' as const,
|
||||
flexDirection: 'row' as const,
|
||||
position: 'absolute' as const,
|
||||
...(isOverflow
|
||||
? {top: 4, right: 4, gap: 4}
|
||||
: !isMobile && images.length < 3
|
||||
? {top: 8, right: 8, gap: 8}
|
||||
: {top: 4, right: 4, gap: 4}),
|
||||
zIndex: 1,
|
||||
},
|
||||
imageStyle: {
|
||||
height: side,
|
||||
width: side,
|
||||
},
|
||||
}
|
||||
}, [images.length, containerInfo, isMobile])
|
||||
? {top: 8, right: 8, gap: 8}
|
||||
: {top: 4, right: 4, gap: 4}),
|
||||
zIndex: 1,
|
||||
},
|
||||
imageStyle: {
|
||||
height: side,
|
||||
width: side,
|
||||
},
|
||||
}
|
||||
}, [images.length, containerInfo, isMobile])
|
||||
|
||||
return images.length !== 0 ? (
|
||||
<>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React from 'react'
|
||||
import {useEffect, useMemo, useRef} from 'react'
|
||||
import {Pressable, useWindowDimensions, View} from 'react-native'
|
||||
import Picker from '@emoji-mart/react'
|
||||
import {msg} from '@lingui/core/macro'
|
||||
@@ -52,9 +52,9 @@ export function EmojiPicker({state, close, pinToTop}: IProps) {
|
||||
const {_} = useLingui()
|
||||
const {height, width} = useWindowDimensions()
|
||||
|
||||
const isShiftDown = React.useRef(false)
|
||||
const isShiftDown = useRef(false)
|
||||
|
||||
const position = React.useMemo(() => {
|
||||
const position = useMemo(() => {
|
||||
if (pinToTop) {
|
||||
return {
|
||||
top: state.pos.top - PICKER_HEIGHT + HEIGHT_OFFSET - 10,
|
||||
@@ -86,7 +86,7 @@ export function EmojiPicker({state, close, pinToTop}: IProps) {
|
||||
}
|
||||
}, [state.pos, height, width, pinToTop])
|
||||
|
||||
React.useEffect(() => {
|
||||
useEffect(() => {
|
||||
if (!state.isOpen) return
|
||||
|
||||
const onKeyDown = (e: KeyboardEvent) => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React from 'react'
|
||||
import {useCallback} from 'react'
|
||||
import {init} from 'emoji-mart'
|
||||
|
||||
/**
|
||||
@@ -11,7 +11,7 @@ let loadRequested = false
|
||||
* {@link https://github.com/missive/emoji-mart/blob/16978d04a766eec6455e2e8bb21cd8dc0b3c7436/README.md?plain=1#L194}
|
||||
*/
|
||||
export function useWebPreloadEmoji({immediate}: {immediate?: boolean} = {}) {
|
||||
const preload = React.useCallback(async () => {
|
||||
const preload = useCallback(async () => {
|
||||
if (loadRequested) return
|
||||
loadRequested = true
|
||||
try {
|
||||
|
||||
@@ -3,7 +3,6 @@ import {View} from 'react-native'
|
||||
import {msg} from '@lingui/core/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
import {Trans} from '@lingui/react/macro'
|
||||
import type React from 'react'
|
||||
|
||||
import {logger} from '#/logger'
|
||||
import * as Toast from '#/view/com/util/Toast'
|
||||
|
||||
Reference in New Issue
Block a user