mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-23 18:17:38 +00:00
Make CHUNK_SIZE a constant
This commit is contained in:
parent
3a9ca10a40
commit
ce1a49acba
3 changed files with 7 additions and 8 deletions
|
|
@ -9,3 +9,4 @@ export const SKIN_CDN = "https://cdn.webampskins.org";
|
|||
export const API_URL = "https://api.webampskins.org";
|
||||
export const SHOW_UPLOAD = window.location.hash.includes("upload");
|
||||
export const HEADING_HEIGHT = 46;
|
||||
export const CHUNK_SIZE = 100;
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import {
|
|||
} from "rxjs/operators";
|
||||
import { search } from "../algolia";
|
||||
import queryParser from "../queryParser";
|
||||
import { API_URL } from "../constants";
|
||||
import { API_URL, CHUNK_SIZE } from "../constants";
|
||||
import * as UploadUtils from "../uploadUtils";
|
||||
|
||||
const urlChangedEpic = (actions) =>
|
||||
|
|
@ -150,15 +150,14 @@ const unloadedSkinEpic = (actions, states) =>
|
|||
actions.pipe(
|
||||
filter((action) => action.type === "REQUEST_UNLOADED_SKIN"),
|
||||
mergeMap(async ({ index }) => {
|
||||
const chunkSize = 100;
|
||||
const chunk = Math.floor(index / (chunkSize - 1));
|
||||
const chunk = Math.floor(index / (CHUNK_SIZE - 1));
|
||||
|
||||
if (chunkState[chunk] != null) {
|
||||
return EMPTY;
|
||||
return null;
|
||||
}
|
||||
chunkState[chunk] = "fetching";
|
||||
const response = await fetch(
|
||||
`${API_URL}/skins?offset=${chunk * chunkSize}&first=${chunkSize}`
|
||||
`${API_URL}/skins?offset=${chunk * CHUNK_SIZE}&first=${CHUNK_SIZE}`
|
||||
);
|
||||
|
||||
const body = await response.json();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { ABOUT_PAGE } from "../constants";
|
||||
import { ABOUT_PAGE, CHUNK_SIZE } from "../constants";
|
||||
|
||||
const defaultState = {
|
||||
searchQuery: null,
|
||||
|
|
@ -13,7 +13,6 @@ const defaultState = {
|
|||
activeContentPage: null,
|
||||
totalNumberOfSkins: null,
|
||||
scale: 0.5,
|
||||
skinChunkData: { chunkSize: 100, numberOfSkins: 64381, chunkFileNames: [] },
|
||||
skins: {},
|
||||
showNsfw: false,
|
||||
fileUploads: {},
|
||||
|
|
@ -173,7 +172,7 @@ export default function reducer(state = defaultState, action) {
|
|||
// TODO: Get chunk size from state
|
||||
// TODO: validate the chunk number is in bounds
|
||||
// TODO: validate that we don't alredy have this chunk
|
||||
newDefaultSkins[action.chunk * 100 + i] = skin.md5;
|
||||
newDefaultSkins[action.chunk * CHUNK_SIZE + i] = skin.md5;
|
||||
});
|
||||
return {
|
||||
...state,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue