mirror of
https://github.com/hex248/sprint.git
synced 2026-02-08 18:33:01 +00:00
sync url params with current states
This commit is contained in:
@@ -69,6 +69,35 @@ export default function App() {
|
|||||||
projectMatched: false,
|
projectMatched: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const initialUrlSyncRef = useRef(false);
|
||||||
|
|
||||||
|
const updateUrlParams = (updates: {
|
||||||
|
orgSlug?: string | null;
|
||||||
|
projectKey?: string | null;
|
||||||
|
issueNumber?: number | null;
|
||||||
|
}) => {
|
||||||
|
const params = new URLSearchParams(window.location.search);
|
||||||
|
|
||||||
|
if (updates.orgSlug !== undefined) {
|
||||||
|
if (updates.orgSlug) params.set("o", updates.orgSlug);
|
||||||
|
else params.delete("o");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (updates.projectKey !== undefined) {
|
||||||
|
if (updates.projectKey) params.set("p", updates.projectKey);
|
||||||
|
else params.delete("p");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (updates.issueNumber !== undefined) {
|
||||||
|
if (updates.issueNumber != null) params.set("i", `${updates.issueNumber}`);
|
||||||
|
else params.delete("i");
|
||||||
|
}
|
||||||
|
|
||||||
|
const search = params.toString();
|
||||||
|
const nextUrl = `${window.location.pathname}${search ? `?${search}` : ""}`;
|
||||||
|
window.history.replaceState(null, "", nextUrl);
|
||||||
|
};
|
||||||
|
|
||||||
const refetchOrganisations = async (options?: { selectOrganisationId?: number }) => {
|
const refetchOrganisations = async (options?: { selectOrganisationId?: number }) => {
|
||||||
try {
|
try {
|
||||||
await organisation.byUser({
|
await organisation.byUser({
|
||||||
@@ -275,6 +304,29 @@ export default function App() {
|
|||||||
void refetchIssues();
|
void refetchIssues();
|
||||||
}, [selectedProject]);
|
}, [selectedProject]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (initialUrlSyncRef.current) return;
|
||||||
|
|
||||||
|
if (deepLinkParams.orgSlug || deepLinkParams.projectKey || deepLinkParams.issueNumber != null) {
|
||||||
|
initialUrlSyncRef.current = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (new URLSearchParams(window.location.search).toString() !== "") {
|
||||||
|
initialUrlSyncRef.current = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selectedOrganisation && selectedProject) {
|
||||||
|
updateUrlParams({
|
||||||
|
orgSlug: selectedOrganisation.Organisation.slug.toLowerCase(),
|
||||||
|
projectKey: selectedProject.Project.key.toLowerCase(),
|
||||||
|
issueNumber: null,
|
||||||
|
});
|
||||||
|
initialUrlSyncRef.current = true;
|
||||||
|
}
|
||||||
|
}, [deepLinkParams, selectedOrganisation, selectedProject]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main className={`w-full h-screen flex flex-col gap-${BREATHING_ROOM} p-${BREATHING_ROOM}`}>
|
<main className={`w-full h-screen flex flex-col gap-${BREATHING_ROOM} p-${BREATHING_ROOM}`}>
|
||||||
{/* header area */}
|
{/* header area */}
|
||||||
@@ -287,6 +339,11 @@ export default function App() {
|
|||||||
onSelectedOrganisationChange={(org) => {
|
onSelectedOrganisationChange={(org) => {
|
||||||
setSelectedOrganisation(org);
|
setSelectedOrganisation(org);
|
||||||
localStorage.setItem("selectedOrganisationId", `${org?.Organisation.id}`);
|
localStorage.setItem("selectedOrganisationId", `${org?.Organisation.id}`);
|
||||||
|
updateUrlParams({
|
||||||
|
orgSlug: org?.Organisation.slug.toLowerCase() ?? null,
|
||||||
|
projectKey: null,
|
||||||
|
issueNumber: null,
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
onCreateOrganisation={async (organisationId) => {
|
onCreateOrganisation={async (organisationId) => {
|
||||||
await refetchOrganisations({ selectOrganisationId: organisationId });
|
await refetchOrganisations({ selectOrganisationId: organisationId });
|
||||||
@@ -304,6 +361,10 @@ export default function App() {
|
|||||||
setSelectedProject(project);
|
setSelectedProject(project);
|
||||||
localStorage.setItem("selectedProjectId", `${project?.Project.id}`);
|
localStorage.setItem("selectedProjectId", `${project?.Project.id}`);
|
||||||
setSelectedIssue(null);
|
setSelectedIssue(null);
|
||||||
|
updateUrlParams({
|
||||||
|
projectKey: project?.Project.key.toLowerCase() ?? null,
|
||||||
|
issueNumber: null,
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
onCreateProject={async (projectId) => {
|
onCreateProject={async (projectId) => {
|
||||||
if (!selectedOrganisation) return;
|
if (!selectedOrganisation) return;
|
||||||
@@ -375,8 +436,13 @@ export default function App() {
|
|||||||
columns={{ description: false }}
|
columns={{ description: false }}
|
||||||
statuses={selectedOrganisation.Organisation.statuses}
|
statuses={selectedOrganisation.Organisation.statuses}
|
||||||
issueSelectAction={(issue) => {
|
issueSelectAction={(issue) => {
|
||||||
if (issue.Issue.id === selectedIssue?.Issue.id) setSelectedIssue(null);
|
if (issue.Issue.id === selectedIssue?.Issue.id) {
|
||||||
else setSelectedIssue(issue);
|
setSelectedIssue(null);
|
||||||
|
updateUrlParams({ issueNumber: null });
|
||||||
|
} else {
|
||||||
|
setSelectedIssue(issue);
|
||||||
|
updateUrlParams({ issueNumber: issue.Issue.number });
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
className="border w-full flex-shrink"
|
className="border w-full flex-shrink"
|
||||||
/>
|
/>
|
||||||
@@ -393,7 +459,10 @@ export default function App() {
|
|||||||
issueData={selectedIssue}
|
issueData={selectedIssue}
|
||||||
members={members}
|
members={members}
|
||||||
statuses={selectedOrganisation.Organisation.statuses}
|
statuses={selectedOrganisation.Organisation.statuses}
|
||||||
close={() => setSelectedIssue(null)}
|
close={() => {
|
||||||
|
setSelectedIssue(null);
|
||||||
|
updateUrlParams({ issueNumber: null });
|
||||||
|
}}
|
||||||
onIssueUpdate={refetchIssues}
|
onIssueUpdate={refetchIssues}
|
||||||
onIssueDelete={handleIssueDelete}
|
onIssueDelete={handleIssueDelete}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user