mirror of
https://github.com/hex248/sprint.git
synced 2026-02-07 18:23:03 +00:00
fix: url params (SelectionProvider) weren't populating in the right places and and the right times
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import type { IssueResponse, OrganisationResponse, ProjectResponse } from "@sprint/shared";
|
import type { IssueResponse, OrganisationResponse, ProjectResponse } from "@sprint/shared";
|
||||||
import type { ReactNode } from "react";
|
import type { ReactNode } from "react";
|
||||||
import { createContext, useCallback, useContext, useEffect, useMemo, useState } from "react";
|
import { createContext, useCallback, useContext, useEffect, useMemo, useState } from "react";
|
||||||
|
import { useLocation } from "react-router-dom";
|
||||||
|
|
||||||
type SelectionContextValue = {
|
type SelectionContextValue = {
|
||||||
selectedOrganisationId: number | null;
|
selectedOrganisationId: number | null;
|
||||||
@@ -69,6 +70,8 @@ const updateUrlParams = (updates: {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export function SelectionProvider({ children }: { children: ReactNode }) {
|
export function SelectionProvider({ children }: { children: ReactNode }) {
|
||||||
|
const location = useLocation();
|
||||||
|
|
||||||
const initialParams = useMemo(() => {
|
const initialParams = useMemo(() => {
|
||||||
const params = new URLSearchParams(window.location.search);
|
const params = new URLSearchParams(window.location.search);
|
||||||
const orgSlug = params.get("o")?.trim().toLowerCase() ?? "";
|
const orgSlug = params.get("o")?.trim().toLowerCase() ?? "";
|
||||||
@@ -153,24 +156,25 @@ export function SelectionProvider({ children }: { children: ReactNode }) {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const params = new URLSearchParams(window.location.search);
|
const params = new URLSearchParams(window.location.search);
|
||||||
const allowIssue = window.location.pathname.startsWith("/issues");
|
const pathname = location.pathname;
|
||||||
|
const allowParams = pathname.startsWith("/issues") || pathname.startsWith("/timeline");
|
||||||
const updates: {
|
const updates: {
|
||||||
orgSlug?: string | null;
|
orgSlug?: string | null;
|
||||||
projectKey?: string | null;
|
projectKey?: string | null;
|
||||||
issueNumber?: number | null;
|
issueNumber?: number | null;
|
||||||
} = {};
|
} = {};
|
||||||
|
|
||||||
if (!params.get("o")) {
|
if (allowParams && !params.get("o")) {
|
||||||
const storedOrgSlug = readStoredString("selectedOrganisationSlug");
|
const storedOrgSlug = readStoredString("selectedOrganisationSlug");
|
||||||
if (storedOrgSlug) updates.orgSlug = storedOrgSlug;
|
if (storedOrgSlug) updates.orgSlug = storedOrgSlug;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!params.get("p")) {
|
if (allowParams && !params.get("p")) {
|
||||||
const storedProjectKey = readStoredString("selectedProjectKey");
|
const storedProjectKey = readStoredString("selectedProjectKey");
|
||||||
if (storedProjectKey) updates.projectKey = storedProjectKey;
|
if (storedProjectKey) updates.projectKey = storedProjectKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (allowIssue && !params.get("i")) {
|
if (allowParams && !params.get("i")) {
|
||||||
const storedIssueNumber = readStoredId("selectedIssueNumber");
|
const storedIssueNumber = readStoredId("selectedIssueNumber");
|
||||||
if (storedIssueNumber != null) updates.issueNumber = storedIssueNumber;
|
if (storedIssueNumber != null) updates.issueNumber = storedIssueNumber;
|
||||||
}
|
}
|
||||||
@@ -178,7 +182,7 @@ export function SelectionProvider({ children }: { children: ReactNode }) {
|
|||||||
if (Object.keys(updates).length > 0) {
|
if (Object.keys(updates).length > 0) {
|
||||||
updateUrlParams(updates);
|
updateUrlParams(updates);
|
||||||
}
|
}
|
||||||
}, []);
|
}, [location.pathname]);
|
||||||
|
|
||||||
const value = useMemo<SelectionContextValue>(
|
const value = useMemo<SelectionContextValue>(
|
||||||
() => ({
|
() => ({
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
|
|||||||
<ThemeProvider defaultTheme="dark" storageKey="vite-ui-theme">
|
<ThemeProvider defaultTheme="dark" storageKey="vite-ui-theme">
|
||||||
<QueryProvider>
|
<QueryProvider>
|
||||||
<SessionProvider>
|
<SessionProvider>
|
||||||
<SelectionProvider>
|
<BrowserRouter>
|
||||||
<BrowserRouter>
|
<SelectionProvider>
|
||||||
<Routes>
|
<Routes>
|
||||||
{/* public routes */}
|
{/* public routes */}
|
||||||
<Route path="/" element={<Landing />} />
|
<Route path="/" element={<Landing />} />
|
||||||
@@ -57,10 +57,10 @@ ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
|
|||||||
|
|
||||||
<Route path="*" element={<NotFound />} />
|
<Route path="*" element={<NotFound />} />
|
||||||
</Routes>
|
</Routes>
|
||||||
</BrowserRouter>
|
</SelectionProvider>
|
||||||
<ActiveTimersOverlay />
|
</BrowserRouter>
|
||||||
<Toaster visibleToasts={1} duration={2000} />
|
<ActiveTimersOverlay />
|
||||||
</SelectionProvider>
|
<Toaster visibleToasts={1} duration={2000} />
|
||||||
</SessionProvider>
|
</SessionProvider>
|
||||||
</QueryProvider>
|
</QueryProvider>
|
||||||
</ThemeProvider>
|
</ThemeProvider>
|
||||||
|
|||||||
Reference in New Issue
Block a user