Radish alpha
r
Radicle web interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
Fix querystring handling for issues and patches
Sebastian Martinez committed 3 years ago
commit d6dbc16909c31b8e3f116df3fd912d32f602ba7b
parent 25edd969f8b36e4136c9c22a54d3c4576aa12d29
4 files changed +36 -30
modified src/lib/router.ts
@@ -66,6 +66,10 @@ export function projectLinkHref(
  }
}

+
function sanitizeQueryString(queryString: string): string {
+
  return queryString.startsWith("?") ? queryString.substring(1) : queryString;
+
}
+

export function updateProjectRoute(
  projectRouteParams: Partial<ProjectsParams>,
  opts: { replace: boolean } = { replace: false },
@@ -226,7 +230,6 @@ function pathToRoute(path: string): Route | null {
              resource: "projects",
              params: {
                ...params,
-
                search: url.search,
                seed: host,
                id,
              },
@@ -263,7 +266,6 @@ function pathToRoute(path: string): Route | null {
                params: {
                  ...params,
                  id,
-
                  search: url.search,
                  profile: resource,
                },
              };
@@ -311,31 +313,29 @@ export function routeToPath(route: Route) {
    }

    let suffix = "";
-
    if (!route.params.route) {
-
      if (route.params.revision) {
+
    if (route.params.route) {
+
      suffix = `/${route.params.route}`;
+
    } else {
+
      if (
+
        (route.params.view.resource === "tree" ||
+
          route.params.view.resource === "commits" ||
+
          route.params.view.resource === "history") &&
+
        route.params.revision
+
      ) {
        suffix = `/${route.params.revision}`;
      }
      if (route.params.path && route.params.path !== "/") {
        suffix += `/${route.params.path}`;
      }
-
      if (route.params.line) {
-
        suffix += `#${route.params.line}`;
-
      } else if (route.params.hash) {
-
        suffix += `#${route.params.hash}`;
-
      }
-
      if (route.params.search) {
-
        suffix += `${route.params.search}`;
-
      }
-
    } else {
-
      suffix = `/${route.params.route}`;
-
      if (route.params.search) {
-
        suffix += `${route.params.search}`;
-
      }
-
      if (route.params.line) {
-
        suffix += `#${route.params.line}`;
-
      } else if (route.params.hash) {
-
        suffix += `#${route.params.hash}`;
-
      }
+
    }
+

+
    if (route.params.search) {
+
      suffix += `?${route.params.search}`;
+
    }
+
    if (route.params.line) {
+
      suffix += `#${route.params.line}`;
+
    } else if (route.params.hash) {
+
      suffix += `#${route.params.hash}`;
    }

    if (route.params.view.resource === "tree") {
@@ -399,6 +399,7 @@ function resolveProjectRoute(
      peer,
      path: undefined,
      revision: undefined,
+
      search: undefined,
      line: line?.substring(1),
      hash: hash?.substring(1),
      route: segments.join("/"),
@@ -410,6 +411,7 @@ function resolveProjectRoute(
      peer,
      path: undefined,
      revision: undefined,
+
      search: undefined,
      route: segments.join("/"),
    };
  } else if (content === "commits") {
@@ -419,6 +421,7 @@ function resolveProjectRoute(
      peer,
      path: undefined,
      revision: undefined,
+
      search: undefined,
      route: segments.join("/"),
    };
  } else if (content === "patches") {
@@ -429,6 +432,7 @@ function resolveProjectRoute(
        id,
        peer,
        path: undefined,
+
        search: undefined,
        revision: undefined,
      };
    } else {
@@ -436,6 +440,7 @@ function resolveProjectRoute(
        view: { resource: "patches" },
        id,
        peer,
+
        search: sanitizeQueryString(url.search),
        path: undefined,
        revision: undefined,
      };
@@ -449,12 +454,14 @@ function resolveProjectRoute(
        peer,
        path: undefined,
        revision: undefined,
+
        search: undefined,
      };
    } else {
      return {
        view: { resource: "issues" },
        id,
        peer,
+
        search: sanitizeQueryString(url.search),
        path: undefined,
        revision: undefined,
      };
modified src/views/projects/Header.svelte
@@ -30,6 +30,7 @@
      },
      id: project.id,
      revision: revision,
+
      search: undefined,
      ...(keepSourceInPath ? null : { revision: undefined, path: undefined }),
    });
  };
modified src/views/projects/Issues.svelte
@@ -63,11 +63,10 @@
  <div style="margin-bottom: 1rem;">
    <ToggleButton
      {options}
-
      on:select={e => {
+
      on:select={e =>
        router.updateProjectRoute({
-
          search: e.detail,
-
        });
-
      }}
+
          search: `state=${e.detail}`,
+
        })}
      active={state} />
  </div>

modified src/views/projects/Patches.svelte
@@ -63,11 +63,10 @@
  <div style="margin-bottom: 1rem;">
    <ToggleButton
      {options}
-
      on:select={e => {
+
      on:select={e =>
        router.updateProjectRoute({
-
          search: e.detail,
-
        });
-
      }}
+
          search: `state=${e.detail}`,
+
        })}
      active={state} />
  </div>