Merge branch 'main' of https://github.com/spicecat/qOverflow
This commit is contained in:
commit
29651a37c8
4 changed files with 22 additions and 26 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,17 +3,13 @@ import { PaginatedList } from 'components';
|
|||
import { useSearchParams } from 'react-router-dom';
|
||||
|
||||
const rowsPerPage = 5;
|
||||
export default function PaginatedListController({
|
||||
concat = true,
|
||||
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);
|
||||
|
|
@ -21,15 +17,17 @@ export default function PaginatedListController({
|
|||
loadData();
|
||||
};
|
||||
|
||||
const loadData = async () => {
|
||||
const newData = await getData(
|
||||
concat ? data[data.length - 1] ?? {} : {}
|
||||
);
|
||||
if (newData.length)
|
||||
if (concat) setData(data.concat(newData));
|
||||
else setData(newData);
|
||||
else setLoad(false);
|
||||
};
|
||||
const loadData = async (clear) => {
|
||||
const newData = await getData(clear ? {} : data[data.length - 1] ?? {});
|
||||
|
||||
if (newData?.length)
|
||||
if (clear)
|
||||
setData(newData);
|
||||
else
|
||||
setData(data.concat(newData));
|
||||
else
|
||||
setLoad(false);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
loadData(true);
|
||||
|
|
|
|||
|
|
@ -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