Skip to content

Commit

Permalink
fix: includeExclusiveSubmissions
Browse files Browse the repository at this point in the history
  • Loading branch information
std-microblock committed Feb 14, 2024
1 parent 438291c commit 950c7b5
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 27 deletions.
Binary file modified resources/dist.rc
Binary file not shown.
4 changes: 3 additions & 1 deletion src/celemod-ui/src/api/wegfan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ export const searchSubmission = async ({
if (search) params.set("search", search);
if (sort) params.set("sort", sort);
if (includeExclusiveSubmissions) params.set("includeExclusiveSubmissions", includeExclusiveSubmissions.toString());
return fetch(`https://celeste.weg.fan/api/v2/submission/search?${params.toString()}`, {
const url = `https://celeste.weg.fan/api/v2/submission/search?${params.toString()}`;
console.log(url);
return fetch(url, {
headers: {
'User-Agent': celemodUA
}
Expand Down
34 changes: 18 additions & 16 deletions src/celemod-ui/src/components/ModList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,8 @@ export const Mod = memo(
<Icon name="i-tick" />
) : downloadTask ? (
downloadTask.state === 'pending' ? (
`${downloadTask.progress}% (${
downloadTask.subtasks.filter((v) => v.state !== 'Finished')
.length
`${downloadTask.progress}% (${downloadTask.subtasks.filter((v) => v.state !== 'Finished')
.length
})`
) : downloadTask.state === 'failed' ? (
<Icon name="i-cross" />
Expand Down Expand Up @@ -371,6 +370,7 @@ export const Mod = memo(
export const ModList = (props: {
mods: Content[];
onLoadMore?: any;
haveMore?: boolean;
modFolder: string;
loading?: boolean;
allowUpScroll: boolean;
Expand Down Expand Up @@ -418,7 +418,7 @@ export const ModList = (props: {
);
const end = Math.ceil(
(refList.current.scrollTop + refList.current.offsetHeight - padding * 2) /
childHeight
childHeight
);
const colWidth = Math.floor((refList.current?.offsetWidth || 0) / 340);
return { start, end, colWidth };
Expand Down Expand Up @@ -480,7 +480,9 @@ export const ModList = (props: {
top: topPaddingDownTop,
behavior: 'smooth',
});
reachedOnce = true;

if (props.haveMore)
reachedOnce = true;
}
} else if (
target >
Expand Down Expand Up @@ -513,7 +515,8 @@ export const ModList = (props: {
top: bottomPaddingUpTop,
behavior: 'smooth',
});
reachedOnce = true;
if (props.haveMore)
reachedOnce = true;
}
} else {
scrollTo({
Expand All @@ -524,7 +527,7 @@ export const ModList = (props: {
}
});
}
}, [props.onLoadMore]);
}, [props.onLoadMore, props.haveMore]);

const formatSize = (size: number) => {
const i = size === 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024));
Expand Down Expand Up @@ -577,16 +580,15 @@ export const ModList = (props: {
})
.map(
(v) =>
({
id: v.gameBananaId.toString(),
name: `${
v.description.includes(v.mods[0].version)
? ''
: v.mods[0].version + '-'
({
id: v.gameBananaId.toString(),
name: `${v.description.includes(v.mods[0].version)
? ''
: v.mods[0].version + '-'
}${v.description}-${v.mods[0].name}`,
size: formatSize(v.size),
url: v.url,
} as FileToDownload)
size: formatSize(v.size),
url: v.url,
} as FileToDownload)
)
);
},
Expand Down
23 changes: 15 additions & 8 deletions src/celemod-ui/src/routes/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Fragment, h } from 'preact';
import { useState, useEffect } from 'preact/hooks';
import { ModList } from '../components/ModList';
import { getMods, Mod, SearchModResp } from '../api/xmao';
import { useCurrentEverestVersion, useGamePath, useMirror } from '../states';
import { currentMirror, useCurrentEverestVersion, useGamePath, useMirror } from '../states';
import './Search.scss';
import { Button } from '../components/Button';
import { Icon } from '../components/Icon';
Expand Down Expand Up @@ -39,8 +39,7 @@ export const Search = () => {
'new' | 'updateAdded' | 'updated' | 'views' | 'likes'
>('likes');
const [currentPage, setCurrentPage] = useState(1);

const [mirror] = useMirror();
const [hasMore, setHasMore] = useState(true);

const fetchModPage = async (page: number) => {
console.log('fetching', page);
Expand All @@ -53,17 +52,20 @@ export const Search = () => {
sort,
section: 'Mod',
size: 25,
includeExclusiveSubmissions: mirror === 'wegfan'
includeExclusiveSubmissions: currentMirror() === 'wegfan'
});
console.log('finished, size:', res.content.length);
setLoading(false);
return res.content;
return res;
};

useEffect(() => {
setMods([]);
setCurrentPage(1);
fetchModPage(1).then(setMods);
fetchModPage(1).then(v=>{
setMods(v.content);
setHasMore(v.hasNextPage);
});
}, [type, search, sort]);

useEffect(() => {
Expand Down Expand Up @@ -123,6 +125,7 @@ export const Search = () => {
allowUpScroll={currentPage > 1}
loading={loading}
mods={mods}
haveMore={hasMore}
onLoadMore={useCallback(
(
type: string,
Expand Down Expand Up @@ -163,7 +166,9 @@ export const Search = () => {
loadingLock.current = true;
fadeOut();
setCurrentPage((v) => {
fetchModPage(v - 1).then((newMods) => {
fetchModPage(v - 1).then((data) => {
const newMods = data.content;
setHasMore(data.hasNextPage);
if (newMods.length === 0) return;
setMods(newMods);
rs(void 0);
Expand All @@ -182,7 +187,9 @@ export const Search = () => {
loadingLock.current = true;
fadeOut();
setCurrentPage((v) => {
fetchModPage(v + 1).then((newMods) => {
fetchModPage(v + 1).then((data) => {
const newMods = data.content;
setHasMore(data.hasNextPage);
if (newMods.length === 0) return;
setMods(newMods);
rs(void 0);
Expand Down
8 changes: 6 additions & 2 deletions src/celemod-ui/src/states.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ function createPersistedState<T>(initial: T, get: (storage: _Storage) => T, set:
},
}));

let refValue = initial;

return [() => {
const { value, set: setData } = useTheState();

Expand All @@ -103,12 +105,14 @@ function createPersistedState<T>(initial: T, get: (storage: _Storage) => T, set:
useEffect(() => {
if (!storage) return;
const data = get(storage);
refValue = data;
data && setData(data)
}, [storage])
}, (() => {
const { value, set: setData } = useTheState();
const { storage, save } = useStorage();
return [value, (data) => {
refValue = data;
setData(data)
if (storage)
set(storage, data, save)
Expand All @@ -117,15 +121,15 @@ function createPersistedState<T>(initial: T, get: (storage: _Storage) => T, set:
set(storage, data, save)
}, 10)
}]
})] as [() => void, () => ([T, (data: T) => void])]
}), () => refValue] as [() => void, () => ([T, (data: T) => void]), () => T]
}

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

export const [initMirror, useMirror] = createPersistedStateByKey('mirror', 'wegfan')
export const [initMirror, useMirror, currentMirror] = createPersistedStateByKey('mirror', 'wegfan')
export const [initGamePath, useGamePath] = createPersistedState<string>('', storage => {
if (storage?.root?.lastGamePath)
return storage.root.lastGamePath
Expand Down

0 comments on commit 950c7b5

Please sign in to comment.