Change `<LoadGap>` to accept an arbitrary parameter

Renaud Chaput 2024-06-14 15:29:34 +02:00
parent 977415ca2e
commit 6d75bc6484
No known key found for this signature in database
GPG Key ID: BCFC859D49B46990
3 changed files with 8 additions and 8 deletions

View File

@ -9,18 +9,18 @@ const messages = defineMessages({
load_more: { id: 'status.load_more', defaultMessage: 'Load more' }, load_more: { id: 'status.load_more', defaultMessage: 'Load more' },
}); });
interface Props { interface Props<T> {
disabled: boolean; disabled: boolean;
maxId: string; param: T;
onClick: (maxId: string) => void; onClick: (params: T) => void;
} }
export const LoadGap: React.FC<Props> = ({ disabled, maxId, onClick }) => { export const LoadGap = <T,>({ disabled, param, onClick }: Props<T>) => {
const intl = useIntl(); const intl = useIntl();
const handleClick = useCallback(() => { const handleClick = useCallback(() => {
onClick(maxId); onClick(param);
}, [maxId, onClick]); }, [param, onClick]);
return ( return (
<button <button

View File

@ -106,7 +106,7 @@ export default class StatusList extends ImmutablePureComponent {
<LoadGap <LoadGap
key={'gap:' + statusIds.get(index + 1)} key={'gap:' + statusIds.get(index + 1)}
disabled={isLoading} disabled={isLoading}
maxId={index > 0 ? statusIds.get(index - 1) : null} param={index > 0 ? statusIds.get(index - 1) : null}
onClick={onLoadMore} onClick={onLoadMore}
/> />
); );

View File

@ -202,7 +202,7 @@ class Notifications extends PureComponent {
<LoadGap <LoadGap
key={'gap:' + notifications.getIn([index + 1, 'id'])} key={'gap:' + notifications.getIn([index + 1, 'id'])}
disabled={isLoading} disabled={isLoading}
maxId={index > 0 ? notifications.getIn([index - 1, 'id']) : null} param={index > 0 ? notifications.getIn([index - 1, 'id']) : null}
onClick={this.handleLoadGap} onClick={this.handleLoadGap}
/> />
) : ( ) : (