Skip to content

Commit 950c7b5

Browse files
fix: includeExclusiveSubmissions
1 parent 438291c commit 950c7b5

File tree

5 files changed

+42
-27
lines changed

5 files changed

+42
-27
lines changed

resources/dist.rc

172 Bytes
Binary file not shown.

src/celemod-ui/src/api/wegfan.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ export const searchSubmission = async ({
144144
if (search) params.set("search", search);
145145
if (sort) params.set("sort", sort);
146146
if (includeExclusiveSubmissions) params.set("includeExclusiveSubmissions", includeExclusiveSubmissions.toString());
147-
return fetch(`https://celeste.weg.fan/api/v2/submission/search?${params.toString()}`, {
147+
const url = `https://celeste.weg.fan/api/v2/submission/search?${params.toString()}`;
148+
console.log(url);
149+
return fetch(url, {
148150
headers: {
149151
'User-Agent': celemodUA
150152
}

src/celemod-ui/src/components/ModList.tsx

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,8 @@ export const Mod = memo(
197197
<Icon name="i-tick" />
198198
) : downloadTask ? (
199199
downloadTask.state === 'pending' ? (
200-
`${downloadTask.progress}% (${
201-
downloadTask.subtasks.filter((v) => v.state !== 'Finished')
202-
.length
200+
`${downloadTask.progress}% (${downloadTask.subtasks.filter((v) => v.state !== 'Finished')
201+
.length
203202
})`
204203
) : downloadTask.state === 'failed' ? (
205204
<Icon name="i-cross" />
@@ -371,6 +370,7 @@ export const Mod = memo(
371370
export const ModList = (props: {
372371
mods: Content[];
373372
onLoadMore?: any;
373+
haveMore?: boolean;
374374
modFolder: string;
375375
loading?: boolean;
376376
allowUpScroll: boolean;
@@ -418,7 +418,7 @@ export const ModList = (props: {
418418
);
419419
const end = Math.ceil(
420420
(refList.current.scrollTop + refList.current.offsetHeight - padding * 2) /
421-
childHeight
421+
childHeight
422422
);
423423
const colWidth = Math.floor((refList.current?.offsetWidth || 0) / 340);
424424
return { start, end, colWidth };
@@ -480,7 +480,9 @@ export const ModList = (props: {
480480
top: topPaddingDownTop,
481481
behavior: 'smooth',
482482
});
483-
reachedOnce = true;
483+
484+
if (props.haveMore)
485+
reachedOnce = true;
484486
}
485487
} else if (
486488
target >
@@ -513,7 +515,8 @@ export const ModList = (props: {
513515
top: bottomPaddingUpTop,
514516
behavior: 'smooth',
515517
});
516-
reachedOnce = true;
518+
if (props.haveMore)
519+
reachedOnce = true;
517520
}
518521
} else {
519522
scrollTo({
@@ -524,7 +527,7 @@ export const ModList = (props: {
524527
}
525528
});
526529
}
527-
}, [props.onLoadMore]);
530+
}, [props.onLoadMore, props.haveMore]);
528531

529532
const formatSize = (size: number) => {
530533
const i = size === 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024));
@@ -577,16 +580,15 @@ export const ModList = (props: {
577580
})
578581
.map(
579582
(v) =>
580-
({
581-
id: v.gameBananaId.toString(),
582-
name: `${
583-
v.description.includes(v.mods[0].version)
584-
? ''
585-
: v.mods[0].version + '-'
583+
({
584+
id: v.gameBananaId.toString(),
585+
name: `${v.description.includes(v.mods[0].version)
586+
? ''
587+
: v.mods[0].version + '-'
586588
}${v.description}-${v.mods[0].name}`,
587-
size: formatSize(v.size),
588-
url: v.url,
589-
} as FileToDownload)
589+
size: formatSize(v.size),
590+
url: v.url,
591+
} as FileToDownload)
590592
)
591593
);
592594
},

src/celemod-ui/src/routes/Search.tsx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Fragment, h } from 'preact';
33
import { useState, useEffect } from 'preact/hooks';
44
import { ModList } from '../components/ModList';
55
import { getMods, Mod, SearchModResp } from '../api/xmao';
6-
import { useCurrentEverestVersion, useGamePath, useMirror } from '../states';
6+
import { currentMirror, useCurrentEverestVersion, useGamePath, useMirror } from '../states';
77
import './Search.scss';
88
import { Button } from '../components/Button';
99
import { Icon } from '../components/Icon';
@@ -39,8 +39,7 @@ export const Search = () => {
3939
'new' | 'updateAdded' | 'updated' | 'views' | 'likes'
4040
>('likes');
4141
const [currentPage, setCurrentPage] = useState(1);
42-
43-
const [mirror] = useMirror();
42+
const [hasMore, setHasMore] = useState(true);
4443

4544
const fetchModPage = async (page: number) => {
4645
console.log('fetching', page);
@@ -53,17 +52,20 @@ export const Search = () => {
5352
sort,
5453
section: 'Mod',
5554
size: 25,
56-
includeExclusiveSubmissions: mirror === 'wegfan'
55+
includeExclusiveSubmissions: currentMirror() === 'wegfan'
5756
});
5857
console.log('finished, size:', res.content.length);
5958
setLoading(false);
60-
return res.content;
59+
return res;
6160
};
6261

6362
useEffect(() => {
6463
setMods([]);
6564
setCurrentPage(1);
66-
fetchModPage(1).then(setMods);
65+
fetchModPage(1).then(v=>{
66+
setMods(v.content);
67+
setHasMore(v.hasNextPage);
68+
});
6769
}, [type, search, sort]);
6870

6971
useEffect(() => {
@@ -123,6 +125,7 @@ export const Search = () => {
123125
allowUpScroll={currentPage > 1}
124126
loading={loading}
125127
mods={mods}
128+
haveMore={hasMore}
126129
onLoadMore={useCallback(
127130
(
128131
type: string,
@@ -163,7 +166,9 @@ export const Search = () => {
163166
loadingLock.current = true;
164167
fadeOut();
165168
setCurrentPage((v) => {
166-
fetchModPage(v - 1).then((newMods) => {
169+
fetchModPage(v - 1).then((data) => {
170+
const newMods = data.content;
171+
setHasMore(data.hasNextPage);
167172
if (newMods.length === 0) return;
168173
setMods(newMods);
169174
rs(void 0);
@@ -182,7 +187,9 @@ export const Search = () => {
182187
loadingLock.current = true;
183188
fadeOut();
184189
setCurrentPage((v) => {
185-
fetchModPage(v + 1).then((newMods) => {
190+
fetchModPage(v + 1).then((data) => {
191+
const newMods = data.content;
192+
setHasMore(data.hasNextPage);
186193
if (newMods.length === 0) return;
187194
setMods(newMods);
188195
rs(void 0);

src/celemod-ui/src/states.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ function createPersistedState<T>(initial: T, get: (storage: _Storage) => T, set:
9595
},
9696
}));
9797

98+
let refValue = initial;
99+
98100
return [() => {
99101
const { value, set: setData } = useTheState();
100102

@@ -103,12 +105,14 @@ function createPersistedState<T>(initial: T, get: (storage: _Storage) => T, set:
103105
useEffect(() => {
104106
if (!storage) return;
105107
const data = get(storage);
108+
refValue = data;
106109
data && setData(data)
107110
}, [storage])
108111
}, (() => {
109112
const { value, set: setData } = useTheState();
110113
const { storage, save } = useStorage();
111114
return [value, (data) => {
115+
refValue = data;
112116
setData(data)
113117
if (storage)
114118
set(storage, data, save)
@@ -117,15 +121,15 @@ function createPersistedState<T>(initial: T, get: (storage: _Storage) => T, set:
117121
set(storage, data, save)
118122
}, 10)
119123
}]
120-
})] as [() => void, () => ([T, (data: T) => void])]
124+
}), () => refValue] as [() => void, () => ([T, (data: T) => void]), () => T]
121125
}
122126

123127
const createPersistedStateByKey = <T>(key: string, defaultValue: T) => createPersistedState<T>(defaultValue, storage => storage.root[key], (storage, data, save) => {
124128
storage.root[key] = data;
125129
save()
126130
})
127131

128-
export const [initMirror, useMirror] = createPersistedStateByKey('mirror', 'wegfan')
132+
export const [initMirror, useMirror, currentMirror] = createPersistedStateByKey('mirror', 'wegfan')
129133
export const [initGamePath, useGamePath] = createPersistedState<string>('', storage => {
130134
if (storage?.root?.lastGamePath)
131135
return storage.root.lastGamePath

0 commit comments

Comments
 (0)