Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Images are not loading when pulling them in from firebase firestore #1

Closed
Lewis-Seekio opened this issue Apr 8, 2021 · 8 comments
Closed
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@Lewis-Seekio
Copy link

Hi there, this probably isnt a problem with the repo, more me not understanding how to do this properly.

Here is where I pull in the product from firebase:

useEffect(() => {
        if (listingID === '') {
            window.alert("no id")
        } else {
            var docRef = db.collection("listings").doc(listingID);
            docRef.get().then((doc) => {
                if (doc.exists) {
                    setListing(doc.data());
                } else {
                    console.log("No such document!");
                }
            }).catch((error) => {
                console.log("Error getting document:", error);
            });
        }
    }, [])

And then I assign the photos from the product data to "images" and follow the object pattern that the carousel requires:

const [images, setImages] = useState([]);
useEffect(() => {
        if (listing.listingPhotos != null) {
            console.log("SETTING IMAGES");
            listing.listingPhotos.forEach(element => {
                var imageURL = {
                    src: element
                }
                setImages(images => [...images, imageURL]);
            });
        }
    }, [listing])

And then in my jsx:

return (
        <div className="listingPage">
            <div className="listingPage__main">
                <div className="listingPage__left"></div>
                <div className="listingPage__center">
                    <div className="listingPage__center__itemContainer">
                        <div class="listingPage__center__itemContainer__gridSection image">
                            <Carousel images={images} />
                        </div>
...

When the page loads, I can see that the images are in the carousel object, however it doesnt render them, so I'm guessing its rendering the carousel before it has the images ready? Im new to react so can anyone give me some guidance how to make it wait until the images are ready? Thanks!
image

@yifaneye
Copy link
Owner

yifaneye commented Apr 8, 2021

Hi @Lewis-Seekio ! Thank you for bringing this issue up! 😄

I replicated the issue you are having locally. I then found that there is something wrong in the code, in line 5 of src/utils/useSlides.js.

I edited that file and tried locally and the issue is gone on my machine. I will get this issue fixed and publish a new version before this coming weekend. 👨🏻‍💻 I will notify you for the new version.

@yifaneye yifaneye self-assigned this Apr 8, 2021
@yifaneye yifaneye added bug Something isn't working good first issue Good for newcomers labels Apr 8, 2021
@Lewis-Seekio
Copy link
Author

Awesome! love the carousel btw, really great work.

多谢!

@yifaneye
Copy link
Owner

yifaneye commented Apr 9, 2021

Thank you for your appreciation!

不用谢!😊

@yifaneye
Copy link
Owner

yifaneye commented Apr 9, 2021

Hi @Lewis-Seekio! I fixed this issue and published a new version. Please install this new version by npm install react-gallery-carousel@0.1.1 --save. In this version, I "fixed a bug where image URLs those are not known ahead of time cannot be placed into the carousel".

@Lewis-Seekio
Copy link
Author

Lewis-Seekio commented Apr 9, 2021

Hi @yifaneye, thanks for the reply! I have updated, Unfortunately it still isn't working :( the same problem persists.

image

@Lewis-Seekio
Copy link
Author

My package.json:

{
    "name": "amazon-clone",
    "version": "0.1.0",
    "private": true,
    "dependencies": {
        "@material-ui/core": "^4.11.3",
        "@material-ui/icons": "^4.11.2",
        "@testing-library/jest-dom": "^5.11.10",
        "@testing-library/react": "^11.2.6",
        "@testing-library/user-event": "^13.1.1",
        "axios": "^0.21.1",
        "classnames": "^2.3.1",
        "firebase": "^8.3.2",
        "github": "^14.0.0",
        "react": "^17.0.2",
        "react-currency-format": "^1.0.0",
        "react-dom": "^17.0.2",
        "react-firebase-hooks": "^3.0.3",
        "react-gallery-carousel": "^0.1.1",
        "react-images-upload": "^1.2.8",
        "react-router": "^5.2.0",
        "react-router-dom": "^5.2.0",
        "react-scripts": "4.0.3",
        "sass": "^1.32.8",
        "uuid": "^8.3.2",
        "web-vitals": "^1.1.1"
    },
    "scripts": {
        "start": "react-scripts start",
        "build": "react-scripts build",
        "test": "react-scripts test",
        "eject": "react-scripts eject"
    },
    "eslintConfig": {
        "extends": [
            "react-app",
            "react-app/jest"
        ]
    },
    "browserslist": {
        "production": [
            ">0.2%",
            "not dead",
            "not op_mini all"
        ],
        "development": [
            "last 1 chrome version",
            "last 1 firefox version",
            "last 1 safari version"
        ]
    }
}

@yifaneye
Copy link
Owner

Hi @Lewis-Seekio ! Thank you for trying the patch version! I am sorry to hear it still does not work for you! I made an example (example 3) at https://github.com/yifaneye/react-gallery-carousel/blob/master/example/src/App.js . Please try setImages at once in your useEffect hook i.e. setImages(listing.listingPhotos.map(image => ({ src: image });

Please see the following screen shot.
SS 2021-04-10 at 15 51 14

@Lewis-Seekio
Copy link
Author

@yifaneye It works perfectly now! awesome!

谢谢你的帮助!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants