fix extended list
This commit is contained in:
parent
a9470e2c99
commit
5f03d8591d
4 changed files with 10 additions and 11 deletions
|
|
@ -29,15 +29,13 @@ export default function Dashboard() {
|
|||
setCurrent(value);
|
||||
};
|
||||
|
||||
const getAnswers = async ({ answer_id }) => {
|
||||
const { error, answers } = await getUserAnswers({ after: answer_id });
|
||||
const getAnswers = async () => {
|
||||
const { error, answers } = await getUserAnswers();
|
||||
if (!error) return answers;
|
||||
};
|
||||
|
||||
const getQuestions = async ({ question_id }) => {
|
||||
const { error, questions } = await getUserQuestions({
|
||||
after: question_id,
|
||||
});
|
||||
const getQuestions = async () => {
|
||||
const { error, questions } = await getUserQuestions();
|
||||
if (!error) return questions;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ export default function Search() {
|
|||
<SearchForm />
|
||||
</CardContent>
|
||||
</Card>
|
||||
<PaginatedList {...{ Component: ListQuestion, getData }} />;
|
||||
<PaginatedList {...{ concat: true, Component: ListQuestion, getData }} />;
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,12 +3,12 @@ import { PaginatedList } from 'components';
|
|||
import { useSearchParams } from 'react-router-dom';
|
||||
|
||||
const rowsPerPage = 5;
|
||||
export default function PaginatedListController({ count, Component, getData, noData }) {
|
||||
export default function PaginatedListController({ concat = false, count, Component, getData, noData }) {
|
||||
const [searchParams] = useSearchParams();
|
||||
|
||||
const [data, setData] = useState([]);
|
||||
const [page, setPage] = useState(1);
|
||||
const [load, setLoad] = useState(true);
|
||||
const [load, setLoad] = useState(concat);
|
||||
|
||||
const handleChangePage = (_, newPage) => {
|
||||
setPage(newPage);
|
||||
|
|
@ -18,6 +18,7 @@ export default function PaginatedListController({ count, Component, getData, noD
|
|||
|
||||
const loadData = async (clear) => {
|
||||
const newData = await getData(clear ? {} : data[data.length - 1] ?? {});
|
||||
|
||||
if (newData?.length)
|
||||
if (clear)
|
||||
setData(newData);
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ import { getAnswerComments, getAnswers, getQuestionComments } from 'services/que
|
|||
export function AnswerCommentsList({ answer_id, comments: count }) {
|
||||
const { questionData: { question_id } } = useQuestion();
|
||||
|
||||
const getData = () =>
|
||||
getAnswerComments(question_id, answer_id)
|
||||
const getData = ({ comment_id }) =>
|
||||
getAnswerComments(question_id, answer_id, { after: comment_id })
|
||||
.then(({ comments }) => comments.map(comment => ({ ...comment, answer_id, question_id })))
|
||||
.catch(() => []);
|
||||
|
||||
|
|
|
|||
Reference in a new issue