Skip to content

Commit

Permalink
Newswires UI: Update pagination logic
Browse files Browse the repository at this point in the history
  • Loading branch information
sb-dev committed Jan 24, 2025
1 parent 9512277 commit 2aec945
Show file tree
Hide file tree
Showing 5 changed files with 297 additions and 343 deletions.
4 changes: 1 addition & 3 deletions newswires/client/src/Feed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ export const Feed = () => {
titleSize="s"
/>
)}
{(status == 'success' ||
status == 'offline' ||
status == 'loading-more') &&
{(status == 'success' || status == 'offline') &&
queryData.results.length > 0 && (
<WireItemTable wires={queryData.results} />
)}
Expand Down
29 changes: 20 additions & 9 deletions newswires/client/src/WireItemTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
useEuiTheme,
} from '@elastic/eui';
import { css } from '@emotion/react';
import { useState } from 'react';
import sanitizeHtml from 'sanitize-html';
import { useSearch } from './context/SearchContext.tsx';
import { formatTimestamp } from './formatTimestamp';
Expand All @@ -32,15 +33,24 @@ const fadeOutBackground = css`
`;

export const WireItemTable = ({ wires }: { wires: WireData[] }) => {
const {
config,
handleSelectItem,
state: { status },
loadMoreResults,
} = useSearch();
const { config, handleSelectItem, loadMoreResults } = useSearch();

const [isLoading, setIsLoading] = useState<boolean>(false);

const selectedWireId = config.itemId;

const handleLoadMoreResults = () => {
if (wires.length > 0) {
setIsLoading(true);

const beforeId = Math.min(...wires.map((wire) => wire.id)).toString();

void loadMoreResults(beforeId).finally(() => {
setIsLoading(false);
});
}
};

return (
<>
<EuiTable
Expand Down Expand Up @@ -71,13 +81,13 @@ export const WireItemTable = ({ wires }: { wires: WireData[] }) => {
</EuiTableBody>
</EuiTable>
<EuiButton
isLoading={status === 'loading-more'}
isLoading={isLoading}
css={css`
margin-top: 12px;
`}
onClick={loadMoreResults}
onClick={handleLoadMoreResults}
>
{status === 'loading-more' ? 'Loading' : 'Load more'}
{isLoading ? 'Loading' : 'Load more'}
</EuiButton>
</>
);
Expand Down Expand Up @@ -118,6 +128,7 @@ const WireDataRow = ({
background-color: ${primaryBgColor};
border-left: 4px solid ${theme.euiTheme.colors.accent};
}
border-left: 4px solid
${selected ? theme.euiTheme.colors.primary : 'transparent'};
${isFromRefresh ? fadeOutBackground : ''}
Expand Down
Loading

0 comments on commit 2aec945

Please sign in to comment.