修复空间内重复加载帖子bug

This commit is contained in:
yezian 2024-04-25 17:09:00 +08:00
parent d16df073a9
commit 33f076f2e9
3 changed files with 15 additions and 0 deletions

View File

@ -16,9 +16,12 @@ export default function AllSpacePosts({ zid }) {
const [data, setData] = useState([]); const [data, setData] = useState([]);
const [offset, setOffset] = useState(0); const [offset, setOffset] = useState(0);
const [more, setMore] = useState(1); const [more, setMore] = useState(1);
const [isFetching, setIsFetching] = useState(false);
const getData = async () => { const getData = async () => {
if (zid === undefined) return; if (zid === undefined) return;
if (!more) return; if (!more) return;
if (isFetching) return;
setIsFetching(true);
const apiUrl = process.env.EXPO_PUBLIC_API_URL; const apiUrl = process.env.EXPO_PUBLIC_API_URL;
try { try {
const base = await baseRequest(); const base = await baseRequest();
@ -54,6 +57,8 @@ export default function AllSpacePosts({ zid }) {
setMore(_data.data.more); setMore(_data.data.more);
} catch (error) { } catch (error) {
console.error(error); console.error(error);
} finally {
setIsFetching(false);
} }
}; };

View File

@ -16,9 +16,12 @@ export default function IronFanSpacePosts({ zid }) {
const [data, setData] = useState([]); const [data, setData] = useState([]);
const [offset, setOffset] = useState(0); const [offset, setOffset] = useState(0);
const [more, setMore] = useState(1); const [more, setMore] = useState(1);
const [isFetching, setIsFetching] = useState(false);
const getData = async () => { const getData = async () => {
if (zid === undefined) return; if (zid === undefined) return;
if (!more) return; if (!more) return;
if (isFetching) return;
setIsFetching(true);
const apiUrl = process.env.EXPO_PUBLIC_API_URL; const apiUrl = process.env.EXPO_PUBLIC_API_URL;
try { try {
const base = await baseRequest(); const base = await baseRequest();
@ -56,6 +59,8 @@ export default function IronFanSpacePosts({ zid }) {
setMore(_data.data.more); setMore(_data.data.more);
} catch (error) { } catch (error) {
console.error(error); console.error(error);
} finally {
setIsFetching(false);
} }
}; };

View File

@ -16,9 +16,12 @@ export default function SuperFanSpacePosts({ zid }) {
const [data, setData] = useState([]); const [data, setData] = useState([]);
const [offset, setOffset] = useState(0); const [offset, setOffset] = useState(0);
const [more, setMore] = useState(1); const [more, setMore] = useState(1);
const [isFetching, setIsFetching] = useState(false);
const getData = async () => { const getData = async () => {
if (zid === undefined) return; if (zid === undefined) return;
if (!more) return; if (!more) return;
if (isFetching) return;
setIsFetching(true);
const apiUrl = process.env.EXPO_PUBLIC_API_URL; const apiUrl = process.env.EXPO_PUBLIC_API_URL;
try { try {
const base = await baseRequest(); const base = await baseRequest();
@ -55,6 +58,8 @@ export default function SuperFanSpacePosts({ zid }) {
setMore(_data.data.more); setMore(_data.data.more);
} catch (error) { } catch (error) {
console.error(error); console.error(error);
} finally {
setIsFetching(false);
} }
}; };