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

fix: add query on member select #183

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions src/components/Members/MembersGrid/MembersGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ const tryRequire = (imgPath: string) => {
}
};

const updateNameQueryParam = (name: string, lastname: string) => {
const currentUrl = window.location.href;

const newQueryParam = `name=${name}%20${lastname}`;
let updatedUrl;
const questionMark = currentUrl.indexOf("?");
if (questionMark !== -1) {
updatedUrl = currentUrl.substring(0, questionMark) + "?" + newQueryParam;
} else {
updatedUrl = currentUrl + "?" + newQueryParam;
}

window.history.pushState({ path: updatedUrl }, "", updatedUrl);
};

function MembersGrid() {
const [showModal, setShowModal] = useState(false);
const [firstLoad, setFirstLoad] = useState(false);
Expand Down Expand Up @@ -231,6 +246,8 @@ function MembersGrid() {
setShowModal(true);
setMemberIndex(index);
setActive(member.status !== "inactive");
if (!firstLoad) setFirstLoad(true); // Remove the first load flag
updateNameQueryParam(member.name, member.lastname);
}}
>
<div className="member-image-container">
Expand Down Expand Up @@ -267,7 +284,10 @@ function MembersGrid() {
type="text"
className="members-grid-search-bar-input"
placeholder='Try "mechanic", "software", "Aurora"'
onChange={(e) => setSearchBarText(e.target.value)}
onChange={(e) => {
setSearchBarText(e.target.value);
if (!firstLoad) setFirstLoad(true); // Remove the first load flag
}}
value={searchBarText}
/>
</div>
Expand All @@ -288,7 +308,13 @@ function MembersGrid() {
timeout={200}
fullHeightHover={false}
indicators={false}
onChange={(next) => setMemberIndex(next)}
onChange={(next) => {
setMemberIndex(next);
updateNameQueryParam(
memberList[next].name,
memberList[next].lastname
);
}}
index={memberIndex}
startAt={memberIndex}
>
Expand Down
Loading