removed extended loading in search
This commit is contained in:
parent
d1dbd011ec
commit
1681bb7952
2 changed files with 10 additions and 12 deletions
|
|
@ -5,14 +5,9 @@ import { SearchForm } from 'controllers/FormControllers';
|
|||
import { PaginatedList } from 'controllers';
|
||||
import { ListQuestion } from 'components';
|
||||
import { searchQuestions } from 'services/questionsServices';
|
||||
import { useEffect } from 'react';
|
||||
|
||||
export default function Search() {
|
||||
const [searchParams, setSearchParams] = useSearchParams()
|
||||
useEffect(() => {
|
||||
setSearchParams()
|
||||
}, [])
|
||||
|
||||
const [searchParams] = useSearchParams();
|
||||
|
||||
const getData = async ({ question_id }) => {
|
||||
let match = {};
|
||||
|
|
@ -32,10 +27,10 @@ export default function Search() {
|
|||
if (creator) regexMatch.creator = creator;
|
||||
|
||||
const text = searchParams.get('text');
|
||||
if (text) regexMatch.text = text.replaceAll(' ', '|') + "gmi";
|
||||
if (text) regexMatch.text = text.replaceAll(' ', '|');// + "gmi";
|
||||
|
||||
const title = searchParams.get('title');
|
||||
if (title) regexMatch.title = title.replaceAll(' ', '|') + "gi";
|
||||
if (title) regexMatch.title = title.replaceAll(' ', '|');// + "gi";
|
||||
|
||||
const { questions } = await searchQuestions({ after: question_id, regexMatch, match })
|
||||
|
||||
|
|
@ -50,7 +45,7 @@ export default function Search() {
|
|||
<SearchForm />
|
||||
</CardContent>
|
||||
</Card>
|
||||
<PaginatedList {...{ Component: ListQuestion, getData }} />;
|
||||
<PaginatedList {...{ concat: false, Component: ListQuestion, getData }} />;
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { useEffect, useState } from 'react';
|
|||
import { PaginatedList } from 'components';
|
||||
|
||||
const rowsPerPage = 5;
|
||||
export default function PaginatedListController({ count, Component, getData, noData }) {
|
||||
export default function PaginatedListController({ concat = true, count, Component, getData, noData }) {
|
||||
const [data, setData] = useState([]);
|
||||
const [page, setPage] = useState(1);
|
||||
const [load, setLoad] = useState(true);
|
||||
|
|
@ -14,9 +14,12 @@ export default function PaginatedListController({ count, Component, getData, noD
|
|||
};
|
||||
|
||||
const loadData = async () => {
|
||||
const newData = await getData(data[data.length - 1] ?? {});
|
||||
const newData = await getData(concat ? data[data.length - 1] ?? {} : {});
|
||||
if (newData.length)
|
||||
setData(data.concat(newData));
|
||||
if (concat)
|
||||
setData(data.concat(newData));
|
||||
else
|
||||
setData(newData);
|
||||
else
|
||||
setLoad(false);
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue