Skip to content

Commit

Permalink
Merge pull request #183 from RoBorregos/feat/members/query
Browse files Browse the repository at this point in the history
fix: add query on member select
  • Loading branch information
Oscar-gg authored Feb 8, 2024
2 parents 6704984 + 7f2891c commit 26c1e02
Showing 1 changed file with 28 additions and 2 deletions.
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

0 comments on commit 26c1e02

Please sign in to comment.