From 8f1a777ebbae95481de18670b7763057a3d6894d Mon Sep 17 00:00:00 2001 From: Anton Arnautov Date: Wed, 4 Dec 2024 12:24:57 +0100 Subject: [PATCH] Revert package.json changes, adjust existing --- package.json | 6 +-- src/components/ChannelList/ChannelList.tsx | 8 +-- .../ChannelList/hooks/useChannelListShape.ts | 53 ++++++++++--------- src/components/ChannelList/utils.ts | 2 +- yarn.lock | 45 +++++++--------- 5 files changed, 55 insertions(+), 59 deletions(-) diff --git a/package.json b/package.json index e2d08fb84..0ae609b7b 100644 --- a/package.json +++ b/package.json @@ -225,7 +225,7 @@ "esbuild-plugin-replace": "^1.4.0", "eslint": "7.14.0", "eslint-config-airbnb": "^18.2.1", - "eslint-config-prettier": "^9.1.0", + "eslint-config-prettier": "^6.15.0", "eslint-config-react-app": "^6.0.0", "eslint-import-resolver-alias": "^1.1.2", "eslint-import-resolver-babel-module": "^5.2.0", @@ -236,7 +236,7 @@ "eslint-plugin-jest-dom": "^3.3.0", "eslint-plugin-jsx-a11y": "^6.4.1", "eslint-plugin-node": "^11.1.0", - "eslint-plugin-prettier": "^5.2.1", + "eslint-plugin-prettier": "^3.1.4", "eslint-plugin-promise": "^4.2.1", "eslint-plugin-react": "^7.21.5", "eslint-plugin-react-hooks": "^4.2.0", @@ -252,7 +252,7 @@ "jsdom": "^24.1.1", "lint-staged": "^15.2.1", "moment-timezone": "^0.5.43", - "prettier": "^3.3.3", + "prettier": "^2.2.0", "react": "^18.1.0", "react-dom": "^18.1.0", "react-test-renderer": "^18.1.0", diff --git a/src/components/ChannelList/ChannelList.tsx b/src/components/ChannelList/ChannelList.tsx index 8e791146a..fb58c6541 100644 --- a/src/components/ChannelList/ChannelList.tsx +++ b/src/components/ChannelList/ChannelList.tsx @@ -35,7 +35,7 @@ const DEFAULT_OPTIONS = {}; const DEFAULT_SORT = {}; export type ChannelListProps< - StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics, + StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics > = { /** Additional props for underlying ChannelSearch component and channel search controller, [available props](https://getstream.io/chat/docs/sdk/react/utility-components/channel_search/#props) */ additionalChannelSearchProps?: Omit, 'setChannels'>; @@ -280,10 +280,9 @@ const UnMemoizedChannelList = ({ + const { customHandler, defaultHandler } = usePrepareShapeHandlers({ allowNewMessagesFromUnfilteredChannels, filters, - sort, lockChannelOrder, onAddedToChannel, onChannelDeleted, @@ -295,11 +294,12 @@ const UnMemoizedChannelList = (customFn ?? defaultFn); + useChannelListShape(customHandler ?? defaultHandler); // TODO: maybe move this too useConnectionRecoveredListener(forceUpdate); diff --git a/src/components/ChannelList/hooks/useChannelListShape.ts b/src/components/ChannelList/hooks/useChannelListShape.ts index b05e28947..20d4e8765 100644 --- a/src/components/ChannelList/hooks/useChannelListShape.ts +++ b/src/components/ChannelList/hooks/useChannelListShape.ts @@ -42,15 +42,17 @@ type HandleNotificationMessageNewParameters = Ba lockChannelOrder: boolean; } & Required, 'filters' | 'sort'>>; -type HandleNotificationRemovedFromChannelParameters = - BaseParameters & RepeatedParameters; +type HandleNotificationRemovedFromChannelParameters< + SCG extends ExtendableGenerics +> = BaseParameters & RepeatedParameters; -type HandleNotificationAddedToChannelParameters = - BaseParameters & - RepeatedParameters & { - allowNewMessagesFromUnfilteredChannels: boolean; - lockChannelOrder: boolean; - } & Required, 'sort'>>; +type HandleNotificationAddedToChannelParameters< + SCG extends ExtendableGenerics +> = BaseParameters & + RepeatedParameters & { + allowNewMessagesFromUnfilteredChannels: boolean; + lockChannelOrder: boolean; + } & Required, 'sort'>>; type HandleMemberUpdatedParameters = BaseParameters & { lockChannelOrder: boolean; @@ -99,12 +101,12 @@ export const useChannelListShapeDefaults = () => const handleMessageNew = useCallback( ({ allowNewMessagesFromUnfilteredChannels, - filters, - sort, customHandler, event, + filters, lockChannelOrder, setChannels, + sort, }: HandleMessageNewParameters) => { if (typeof customHandler === 'function') { return customHandler(setChannels, event); @@ -159,11 +161,11 @@ export const useChannelListShapeDefaults = () => const handleNotificationMessageNew = useCallback( async ({ allowNewMessagesFromUnfilteredChannels, - sort, - filters, customHandler, event, + filters, setChannels, + sort, }: HandleNotificationMessageNewParameters) => { if (typeof customHandler === 'function') { return customHandler(setChannels, event); @@ -246,7 +248,7 @@ export const useChannelListShapeDefaults = () => ); const handleMemberUpdated = useCallback( - ({ sort, event, lockChannelOrder, setChannels }: HandleMemberUpdatedParameters) => { + ({ event, lockChannelOrder, setChannels, sort }: HandleMemberUpdatedParameters) => { if (!event.member?.user || event.member.user.id !== client.userID || !event.channel_type) { return; } @@ -258,7 +260,7 @@ export const useChannelListShapeDefaults = () => const considerPinnedChannels = shouldConsiderPinnedChannels(sort); // TODO: extract this and consider single property sort object too - const pinnedAtSort = Array.isArray(sort) ? (sort[0]?.pinned_at ?? null) : null; + const pinnedAtSort = Array.isArray(sort) ? sort[0]?.pinned_at ?? null : null; setChannels((currentChannels) => { const targetChannel = client.channel(channelType, channelId); @@ -448,17 +450,18 @@ type UseDefaultHandleChannelListShapeParameters | 'onMessageNewHandler' | 'onRemovedFromChannel' > & { + setChannels: SetChannels; customHandleChannelListShape?: (data: { - defaults: ReturnType>; + defaults: ReturnType; event: Event; setChannels: SetChannels; }) => void; - setChannels: SetChannels; }; export const usePrepareShapeHandlers = ({ allowNewMessagesFromUnfilteredChannels, customHandleChannelListShape, + filters, lockChannelOrder, onAddedToChannel, onChannelDeleted, @@ -470,7 +473,6 @@ export const usePrepareShapeHandlers = ({ onMessageNewHandler, onRemovedFromChannel, setChannels, - filters, sort, }: UseDefaultHandleChannelListShapeParameters) => { const defaults = useChannelListShapeDefaults(); @@ -480,6 +482,7 @@ export const usePrepareShapeHandlers = ({ const customHandleChannelListShapeRef = useRef<(e: Event) => void>(); customHandleChannelListShapeRef.current = (event: Event) => { + // @ts-expect-error can't use ReturnType> until we upgrade prettier to at least v2.7.0 customHandleChannelListShape?.({ defaults, event, setChannels }); }; @@ -488,33 +491,33 @@ export const usePrepareShapeHandlers = ({ case 'message.new': defaults.handleMessageNew({ allowNewMessagesFromUnfilteredChannels, - sort, - filters, customHandler: onMessageNewHandler, event, + filters, lockChannelOrder, setChannels, + sort, }); break; case 'notification.message_new': defaults.handleNotificationMessageNew({ allowNewMessagesFromUnfilteredChannels, - sort, - filters, customHandler: onMessageNew, event, + filters, lockChannelOrder, setChannels, + sort, }); break; case 'notification.added_to_channel': defaults.handleNotificationAddedToChannel({ allowNewMessagesFromUnfilteredChannels, - sort, customHandler: onAddedToChannel, event, lockChannelOrder, setChannels, + sort, }); break; case 'notification.removed_from_channel': @@ -548,10 +551,10 @@ export const usePrepareShapeHandlers = ({ break; case 'member.updated': defaults.handleMemberUpdated({ - sort, event, lockChannelOrder, setChannels, + sort, }); break; default: @@ -572,8 +575,8 @@ export const usePrepareShapeHandlers = ({ }, [customHandleChannelListShape]); return { - defaultFn, - customFn, + customHandler: customFn, + defaultHandler: defaultFn, }; }; diff --git a/src/components/ChannelList/utils.ts b/src/components/ChannelList/utils.ts index 7d533f8d8..b9cfa83a0 100644 --- a/src/components/ChannelList/utils.ts +++ b/src/components/ChannelList/utils.ts @@ -71,7 +71,7 @@ type MoveChannelUpwardsParams({ channels, channelToMove, diff --git a/yarn.lock b/yarn.lock index 7c4c703c5..65bda3f93 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2114,11 +2114,6 @@ dependencies: "@octokit/openapi-types" "^16.0.0" -"@pkgr/core@^0.1.0": - version "0.1.1" - resolved "https://registry.yarnpkg.com/@pkgr/core/-/core-0.1.1.tgz#1ec17e2edbec25c8306d424ecfbf13c7de1aaa31" - integrity sha512-cq8o4cWH0ibXh9VGi5P20Tu9XF/0fFXl9EUinr9QfTM7a7p0oTA4iJRCQWppXR1Pg8dSM0UCItCkPwsk9qWWYA== - "@playwright/test@^1.42.1": version "1.42.1" resolved "https://registry.yarnpkg.com/@playwright/test/-/test-1.42.1.tgz#9eff7417bcaa770e9e9a00439e078284b301f31c" @@ -5653,10 +5648,12 @@ eslint-config-airbnb@^18.2.1: object.assign "^4.1.2" object.entries "^1.1.2" -eslint-config-prettier@^9.1.0: - version "9.1.0" - resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-9.1.0.tgz#31af3d94578645966c082fcb71a5846d3c94867f" - integrity sha512-NSWl5BFQWEPi1j4TjVNItzYV7dZXZ+wP6I6ZhrBGpChQhZRUaElihE9uRRkcbRnNb76UMKDF3r+WTmNcGPKsqw== +eslint-config-prettier@^6.15.0: + version "6.15.0" + resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-6.15.0.tgz#7f93f6cb7d45a92f1537a70ecc06366e1ac6fed9" + integrity sha512-a1+kOYLR8wMGustcgAjdydMsQ2A/2ipRPwRKUmfYaSxc9ZPcrku080Ctl6zrZzZNs/U82MjSv+qKREkoq3bJaw== + dependencies: + get-stdin "^6.0.0" eslint-config-react-app@^6.0.0: version "6.0.0" @@ -5781,13 +5778,12 @@ eslint-plugin-node@^11.1.0: resolve "^1.10.1" semver "^6.1.0" -eslint-plugin-prettier@^5.2.1: - version "5.2.1" - resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-5.2.1.tgz#d1c8f972d8f60e414c25465c163d16f209411f95" - integrity sha512-gH3iR3g4JfF+yYPaJYkN7jEl9QbweL/YfkoRlNnuIEHEz1vHVlCmWOS+eGGiRuzHQXdJFCOTxRgvju9b8VUmrw== +eslint-plugin-prettier@^3.1.4: + version "3.3.1" + resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-3.3.1.tgz#7079cfa2497078905011e6f82e8dd8453d1371b7" + integrity sha512-Rq3jkcFY8RYeQLgk2cCwuc0P7SEFwDravPhsJZOQ5N4YI4DSg50NyqJ/9gdZHzQlHf8MvafSesbNJCcP/FF6pQ== dependencies: prettier-linter-helpers "^1.0.0" - synckit "^0.9.1" eslint-plugin-promise@^4.2.1: version "4.3.1" @@ -6575,6 +6571,11 @@ get-port@^5.0.0: resolved "https://registry.yarnpkg.com/get-port/-/get-port-5.1.1.tgz#0469ed07563479de6efb986baf053dcd7d4e3193" integrity sha512-g/Q1aTSDOxFpchXC4i8ZWvxA1lnPqx/JHqcpIw0/LX9T8x/GBbi6YnlN5nhaKIFkT8oFsscUKgDJYxfwfS6QsQ== +get-stdin@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-6.0.0.tgz#9e09bf712b360ab9225e812048f71fde9c89657b" + integrity sha512-jp4tHawyV7+fkkSKyvjuLZswblUtz+SQKzSWnBbii16BuZksJlU1wuBYXY75r+duh/llF1ur6oNwi+2ZzjKZ7g== + get-stream@^6.0.0: version "6.0.1" resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-6.0.1.tgz#a262d8eef67aced57c2852ad6167526a43cbf7b7" @@ -10788,10 +10789,10 @@ prettier-linter-helpers@^1.0.0: dependencies: fast-diff "^1.1.2" -prettier@^3.3.3: - version "3.3.3" - resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.3.3.tgz#30c54fe0be0d8d12e6ae61dbb10109ea00d53105" - integrity sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew== +prettier@^2.2.0: + version "2.2.1" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.2.1.tgz#795a1a78dd52f073da0cd42b21f9c91381923ff5" + integrity sha512-PqyhM2yCjg/oKkFPtTGUojv7gnZAoG80ttl45O6x2Ug/rMJw4wcc9k6aaf2hibP7BGVCCM33gZoGjyvt9mm16Q== pretty-format@^26.6.2: version "26.6.2" @@ -12494,14 +12495,6 @@ symlink-or-copy@^1.1.8, symlink-or-copy@^1.2.0, symlink-or-copy@^1.3.1: resolved "https://registry.yarnpkg.com/symlink-or-copy/-/symlink-or-copy-1.3.1.tgz#9506dd64d8e98fa21dcbf4018d1eab23e77f71fe" integrity sha512-0K91MEXFpBUaywiwSSkmKjnGcasG/rVBXFLJz5DrgGabpYD6N+3yZrfD6uUIfpuTu65DZLHi7N8CizHc07BPZA== -synckit@^0.9.1: - version "0.9.2" - resolved "https://registry.yarnpkg.com/synckit/-/synckit-0.9.2.tgz#a3a935eca7922d48b9e7d6c61822ee6c3ae4ec62" - integrity sha512-vrozgXDQwYO72vHjUb/HnFbQx1exDjoKzqx23aXEg2a9VIg2TSFZ8FmeZpTjUCFMYw7mpX4BE2SFu8wI7asYsw== - dependencies: - "@pkgr/core" "^0.1.0" - tslib "^2.6.2" - table@^5.2.3: version "5.4.6" resolved "https://registry.yarnpkg.com/table/-/table-5.4.6.tgz#1292d19500ce3f86053b05f0e8e7e4a3bb21079e"