Wix Member's Profile Page content filtered by memberid not logged in user

I’m having trouble with
site member profiles showing data from a collection from the logged in user, not the member whose profile is being viewed. So right now, if Bob uploaded 2 pictures of cats and Sarah uploaded 3 pictures of dogs, when Bob logs in and visits Sarah’s profile, he sees his own 2 cat pictures, not Sarah’s 3 dog pictures.

What I’m trying to do is have my site members be able to upload images to a public gallery, but then on their own individual profile page show only their upload contributions. And this profile page gallery should be viewable when seen by anyone. The content shown on the profile should only be content uploaded by the user whose profile is being viewed.

What I’ve tried so far is I have added the Wix Members app, and on the default pages that were generated made minor alterations. On account settings, I added an upload and delete button that allows the logged in user to upload an image to a Collection “UserSubmissions”. I have a repeater list that shows all of their submissions, filtered by logged in user, and a delete button. This works great.

On the default Profile page, I added a section “Your Gallery”, and created a gallery showing UserSubmissions filtered by logged in user. This works when a user visits their own profile page. Their personal profile page gallery shows the content they uploaded. The Problem arise when a logged in user visits another members profile. In the “Your Gallery” section I created, it still shows the current logged in user’s submissions, not the submissions of the user they are visiting.

The output is what it should be.

When you add a condition to a dataset that it is supposed to filter the CMS and only show items added by the logged in user, that’s what it will do. So lets say if a user X is on your site and has logged in with their email, then in this case User X becomes the “logged in user”, and the dataset correctly filters the CMS to show the photos added by X. And if X goes to check out the profile pages of Y or Z, the gallery still shows the photos added by user X, because X is still the logged in user, they haven’t logged out of their account yet. They are simply checking out other member’s profiles, and that’s why the content in the gallery does not change.

That was the “why is this happening” part of it. Now for the “how to actually make this work in the way I want to”. For that, you’ll have to write some code, that will detect which member’s profile is currently being viewed and will filter the gallery to show their images, and NOT the logged in user’s all the time. Here’s the reference to the documentation: