fix shift

This commit is contained in:
caranicas 2022-09-25 11:00:53 -04:00
parent 8155e3ef7a
commit 1c1cf58409
2 changed files with 3 additions and 7 deletions

View File

@ -228,12 +228,11 @@ export default function DisplayPanel() {
null null
); );
const len = useImageDisplay((state) => state.len);
const getCurrentImage = useImageDisplay((state) => state.getCurrentImage); const getCurrentImage = useImageDisplay((state) => state.getCurrentImage);
const images = useImageDisplay((state) => state.images); const images = useImageDisplay((state) => state.images);
useEffect(() => { useEffect(() => {
if (len > 0) { if (images.length > 0) {
debugger; debugger;
const cur = getCurrentImage(); const cur = getCurrentImage();
console.log("cur", cur); console.log("cur", cur);
@ -241,7 +240,7 @@ export default function DisplayPanel() {
} else { } else {
setCurrentImage(null); setCurrentImage(null);
} }
}, [len, getCurrentImage]); }, [images, getCurrentImage]);
// useEffect(() => { // useEffect(() => {
// console.log("images CHANGED"); // console.log("images CHANGED");

View File

@ -15,7 +15,6 @@ interface ImageDisplayState {
export const useImageDisplay = create<ImageDisplayState>((set, get) => ({ export const useImageDisplay = create<ImageDisplayState>((set, get) => ({
// imageOptions: new Map<string, any>(), // imageOptions: new Map<string, any>(),
images: [], images: [],
len: 0,
// currentImage: null, // currentImage: null,
// use produce to make sure we don't mutate state // use produce to make sure we don't mutate state
// imageOptions: any // imageOptions: any
@ -25,9 +24,7 @@ export const useImageDisplay = create<ImageDisplayState>((set, get) => ({
// options: imageOptions // options: imageOptions
// state.currentImage = { display: ImageData, imageOptions }; // state.currentImage = { display: ImageData, imageOptions };
// imageOptions // imageOptions
state.images.push({ data: ImageData, info: imageOptions }); state.images.unshift({ data: ImageData, info: imageOptions });
state.len += 1;
debugger
}) })
); );
}, },