Skip to content

Commit af1a69d

Browse files
committed
add fetching more indicator
1 parent 4b65fca commit af1a69d

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

src/components/QuestionTable.tsx

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,17 @@ import { Notification } from '@jupyterlab/apputils';
33
import { listQuestions } from '../services/leetcode';
44
import { LeetCodeQuestion, LeetCodeQuestionQuery } from '../types/leetcode';
55
import QuestionItem from './QuestionItem';
6-
import { Table, Text, Stack, ScrollArea, Skeleton, Group } from '@mantine/core';
6+
import {
7+
Table,
8+
Text,
9+
Stack,
10+
ScrollArea,
11+
Skeleton,
12+
Group,
13+
Transition,
14+
Center,
15+
Loader
16+
} from '@mantine/core';
717
import QuestionQueryKeyword from './QuestionQueryKeyword';
818
import QuestionDifficultyFilter from './QuestionDifficultyFilter';
919
import QuestionStatusFilter from './QuestionStatusFilter';
@@ -20,6 +30,7 @@ const QuestionTable: React.FC<{
2030
const [skip, setSkip] = useState(0);
2131
const [questions, setQuestions] = useState<LeetCodeQuestion[]>([]);
2232
const [hasMore, setHasMore] = useState(true);
33+
const [fetchingMore, setFetchingMore] = useState(false);
2334

2435
const [query, setQuery] = useState<LeetCodeQuestionQuery>({
2536
keyword: '',
@@ -41,6 +52,7 @@ const QuestionTable: React.FC<{
4152
.then(({ problemsetQuestionListV2 }) => {
4253
const qs = fetching ? [] : questions; // fix datarace to ensure distinct key
4354
setFetching(false);
55+
setFetchingMore(false);
4456
const { questions: fetchedQuestions, hasMore: fetchedHasMore } =
4557
problemsetQuestionListV2;
4658
setQuestions(qs.concat(fetchedQuestions));
@@ -103,10 +115,14 @@ const QuestionTable: React.FC<{
103115
updateCompanies={cs => updateQuery({ ...query, companies: cs })}
104116
/>
105117
</Group>
106-
{/* TODO: show fetching more loading icon */}
107118
<ScrollArea
108119
type="scroll"
109-
onBottomReached={() => (hasMore ? setSkip(s => s + limit) : null)}
120+
onBottomReached={() => {
121+
if (!fetchingMore && hasMore) {
122+
setFetchingMore(true);
123+
setSkip(s => s + limit);
124+
}
125+
}}
110126
>
111127
<Table
112128
striped
@@ -116,6 +132,18 @@ const QuestionTable: React.FC<{
116132
>
117133
<Table.Tbody>{getTableRows()}</Table.Tbody>
118134
</Table>
135+
<Transition
136+
mounted={fetchingMore}
137+
transition="fade"
138+
duration={400}
139+
timingFunction="ease"
140+
>
141+
{styles => (
142+
<Center style={styles}>
143+
<Loader size="xs" />
144+
</Center>
145+
)}
146+
</Transition>
119147
</ScrollArea>
120148
</Stack>
121149
);

0 commit comments

Comments
 (0)