Radish alpha
r
Radicle web interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
Refactor BaseUrl string conversion
Rūdolfs Ošiņš committed 2 years ago
commit 41435951c19d0507dd3d6e791fac1f616acc0f59
parent 8f43a57984b934b46d63bf495d638396fdf86c20
8 files changed +21 -24
modified src/lib/utils.ts
@@ -94,8 +94,8 @@ export function formatEditedCaption(
  } edited ${absoluteTimestamp(timestamp)}`;
}

-
export function baseUrlToUrl(baseUrl: BaseUrl): URL {
-
  return new URL(`${baseUrl.scheme}://${baseUrl.hostname}:${baseUrl.port}`);
+
export function baseUrlToString(baseUrl: BaseUrl): string {
+
  return `${baseUrl.scheme}://${baseUrl.hostname}:${baseUrl.port}`;
}

// Generates a publicly shareable link.
modified src/views/home/Index.svelte
@@ -10,7 +10,7 @@

  import { api, httpdStore } from "@app/lib/httpd";
  import { deduplicateStore } from "@app/lib/deduplicateStore";
-
  import { baseUrlToUrl } from "@app/lib/utils";
+
  import { baseUrlToString } from "@app/lib/utils";
  import { getProjectsListingData } from "@app/lib/projects";
  import { handleError } from "@app/views/home/error";
  import { isDelegate } from "@app/lib/roles";
@@ -160,10 +160,7 @@
              </div>
            {:else if localProjects instanceof Error}
              <ErrorMessage
-
                {...handleError(
-
                  localProjects,
-
                  baseUrlToUrl(api.baseUrl).toString(),
-
                )} />
+
                {...handleError(localProjects, baseUrlToString(api.baseUrl))} />
            {:else if !localProjects?.length}
              <div class="heading">No local projects</div>
              <div class="label">
@@ -219,7 +216,7 @@
            <ErrorMessage
              {...handleError(
                preferredSeedProjects,
-
                baseUrlToUrl(api.baseUrl).toString(),
+
                baseUrlToString(api.baseUrl),
              )} />
          {:else}
            <div class="heading">Nothing to see here</div>
modified src/views/nodes/router.ts
@@ -4,7 +4,7 @@ import type { ProjectWithListingData } from "@app/lib/projects";

import { HttpdClient } from "@httpd-client";
import { config } from "@app/lib/config";
-
import { baseUrlToUrl, isLocal } from "@app/lib/utils";
+
import { baseUrlToString, isLocal } from "@app/lib/utils";
import { getProjectsListingData } from "@app/lib/projects";
import { handleError } from "@app/views/nodes/error";

@@ -77,6 +77,6 @@ export async function loadNodeRoute(
      },
    };
  } catch (error: any) {
-
    return handleError(error, baseUrlToUrl(api.baseUrl).toString());
+
    return handleError(error, baseUrlToString(api.baseUrl));
  }
}
modified src/views/projects/Cob/Revision.svelte
@@ -509,9 +509,9 @@
          style:border-radius="var(--border-radius-small">
          <ErrorMessage
            title="Failed to load diff for this revision"
-
            description="Make sure you are able to connect to the seed <code>${utils
-
              .baseUrlToUrl(api.baseUrl)
-
              .toString()}</code>"
+
            description="Make sure you are able to connect to the seed <code>${utils.baseUrlToString(
+
              api.baseUrl,
+
            )}</code>"
            {error} />
        </div>
      {/if}
modified src/views/projects/History.svelte
@@ -10,7 +10,7 @@

  import { COMMITS_PER_PAGE } from "./router";
  import { HttpdClient } from "@httpd-client";
-
  import { baseUrlToUrl } from "@app/lib/utils";
+
  import { baseUrlToString } from "@app/lib/utils";
  import { groupCommits } from "@app/lib/commit";

  import Button from "@app/components/Button.svelte";
@@ -160,9 +160,9 @@
    <div class="message">
      <ErrorMessage
        title="Couldn't load commits"
-
        description="Make sure you are able to connect to the seed <code>${baseUrlToUrl(
+
        description="Make sure you are able to connect to the seed <code>${baseUrlToString(
          api.baseUrl,
-
        ).toString()}</code>"
+
        )}</code>"
        {error} />
    </div>
  {/if}
modified src/views/projects/Issues.svelte
@@ -5,7 +5,7 @@
  import { ISSUES_PER_PAGE } from "./router";
  import { closeFocused } from "@app/components/Popover.svelte";
  import { httpdStore } from "@app/lib/httpd";
-
  import { baseUrlToUrl, isLocal } from "@app/lib/utils";
+
  import { baseUrlToString, isLocal } from "@app/lib/utils";
  import capitalize from "lodash/capitalize";

  import Button from "@app/components/Button.svelte";
@@ -176,9 +176,9 @@
  {#if error}
    <ErrorMessage
      title="Couldn't load issues"
-
      description="Please make sure you are able to connect to the seed <code>${baseUrlToUrl(
+
      description="Please make sure you are able to connect to the seed <code>${baseUrlToString(
        api.baseUrl,
-
      ).toString()}</code>"
+
      )}</code>"
      {error} />
  {/if}

modified src/views/projects/Patches.svelte
@@ -6,7 +6,7 @@

  import { PATCHES_PER_PAGE } from "./router";
  import { httpdStore } from "@app/lib/httpd";
-
  import { baseUrlToUrl, isLocal } from "@app/lib/utils";
+
  import { baseUrlToString, isLocal } from "@app/lib/utils";

  import Button from "@app/components/Button.svelte";
  import DropdownList from "@app/components/DropdownList.svelte";
@@ -195,9 +195,9 @@
  {#if error}
    <ErrorMessage
      title="Couldn't load patches"
-
      description="Please make sure you are able to connect to the seed <code>${baseUrlToUrl(
+
      description="Please make sure you are able to connect to the seed <code>${baseUrlToString(
        api.baseUrl,
-
      ).toString()}</code>"
+
      )}</code>"
      {error} />
  {/if}

modified src/views/projects/error.ts
@@ -1,7 +1,7 @@
import type { ErrorRoute, NotFoundRoute } from "@app/lib/router/definitions";
import type { ProjectRoute } from "@app/views/projects/router";

-
import { baseUrlToUrl, isLocal } from "@app/lib/utils";
+
import { baseUrlToString, isLocal } from "@app/lib/utils";
import { ResponseParseError, ResponseError } from "@httpd-client/lib/fetcher";
import { httpdStore } from "@app/lib/httpd";
import { get } from "svelte/store";
@@ -10,7 +10,7 @@ export function handleError(
  error: Error | ResponseParseError | ResponseError,
  route: ProjectRoute,
): NotFoundRoute | ErrorRoute {
-
  const url = baseUrlToUrl(route.node);
+
  const url = baseUrlToString(route.node);
  if (error instanceof ResponseError && error.status === 404) {
    let subject;