Radish alpha
r
Radicle web interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
Improve handling of `rawPath`
Sebastian Martinez committed 2 years ago
commit b6ac9bd4a7e0cbab2858a18f8af8abdce86f3250
parent 999adff9c179cc10558b9f0232ca6346926eba73
12 files changed +48 -34
modified src/components/Comment.svelte
@@ -143,6 +143,7 @@
    {#if editComment && state !== "read"}
      {@const editComment_ = editComment}
      <ExtendedTextarea
+
        {rawPath}
        {body}
        {enableAttachments}
        submitInProgress={state === "submit"}
modified src/components/CommentToggleInput.svelte
@@ -6,6 +6,7 @@
  export let body: string | undefined = undefined;
  export let placeholder: string | undefined = undefined;
  export let submitCaption: string | undefined = undefined;
+
  export let rawPath: string;
  export let enableAttachments: boolean = false;
  export let inline: boolean = false;
  export let focus: boolean = false;
@@ -31,6 +32,7 @@

{#if state !== "collapsed"}
  <ExtendedTextarea
+
    {rawPath}
    {inline}
    {placeholder}
    {submitCaption}
modified src/components/ExtendedTextarea.svelte
@@ -21,6 +21,7 @@
  export let submitCaption: string = "Comment";
  export let focus: boolean = false;
  export let inline: boolean = false;
+
  export let rawPath: string;
  export let body: string = "";
  export let submitInProgress: boolean = false;

@@ -195,7 +196,7 @@
  </Radio>
  {#if preview}
    <div class="preview">
-
      <Markdown content={body} embeds={newEmbeds} />
+
      <Markdown {rawPath} content={body} embeds={newEmbeds} />
    </div>
  {:else}
    <input
modified src/components/Markdown.svelte
@@ -23,7 +23,7 @@
  // If present, resolve all relative links with respect to this URL
  export let linkBaseUrl: string | undefined = undefined;
  export let path: string = "/";
-
  export let rawPath: string | undefined = undefined;
+
  export let rawPath: string;
  // If present, means we are in a preview context,
  // use this for image previews instead of /raw URLs.
  export let embeds: EmbedWithOid[] | undefined = undefined;
modified src/components/Thread.svelte
@@ -129,6 +129,7 @@
  {#if createReply}
    <div id={`reply-${root.id}`} class="reply">
      <CommentToggleInput
+
        {rawPath}
        inline
        placeholder="Reply to comment"
        on:click={toggleReply}
modified src/lib/utils.ts
@@ -1,5 +1,3 @@
-
import type { BaseUrl } from "@httpd-client";
-

import md5 from "md5";
import bs58 from "bs58";
import twemojiModule from "twemoji";
@@ -10,14 +8,6 @@ export async function toClipboard(text: string): Promise<void> {
  await navigator.clipboard.writeText(text);
}

-
export function getRawBasePath(
-
  id: string,
-
  baseUrl: BaseUrl,
-
  commit: string,
-
): string {
-
  return `${baseUrl.scheme}://${baseUrl.hostname}:${baseUrl.port}/raw/${id}/${commit}`;
-
}
-

export function formatLocationHash(hash: string | null): number | null {
  if (hash && hash.match(/^#L[0-9]+$/)) return parseInt(hash.slice(2));
  return null;
modified src/views/projects/Cob/Revision.svelte
@@ -30,6 +30,7 @@

  export let baseUrl: BaseUrl;
  export let expanded: boolean = false;
+
  export let rawPath: (commit?: string) => string;
  export let patchId: string;
  export let patchState: PatchState;
  export let projectHead: string;
@@ -391,7 +392,7 @@
          {#if revisionDescription && !first}
            <div class="revision-description txt-small">
              <Markdown
-
                rawPath={utils.getRawBasePath(projectId, baseUrl, projectHead)}
+
                rawPath={rawPath(projectHead)}
                content={revisionDescription} />
            </div>
          {/if}
@@ -430,8 +431,8 @@
          <div class="connector" />
          <Thread
            enableAttachments
-
            rawPath={utils.getRawBasePath(projectId, baseUrl, projectHead)}
            thread={element.inner}
+
            rawPath={rawPath(projectHead)}
            {canEditComment}
            {editComment}
            {createReply}
@@ -474,11 +475,11 @@
            class:positive-review={review.verdict === "accept"}
            class:negative-review={review.verdict === "reject"}>
            <CommentComponent
+
              rawPath={rawPath(projectHead)}
              caption={formatVerdict(review.verdict)}
              authorId={author}
              authorAlias={review.author.alias}
              timestamp={review.timestamp}
-
              rawPath={utils.getRawBasePath(projectId, baseUrl, projectHead)}
              body={review.summary ?? ""}>
              <div slot="icon" style:color={verdictIconColor(review.verdict)}>
                {#if review.verdict === "accept"}
modified src/views/projects/Issue.svelte
@@ -38,9 +38,9 @@
  export let baseUrl: BaseUrl;
  export let issue: Issue;
  export let project: Project;
+
  export let rawPath: (commit?: string) => string;
  export let tracking: boolean;

-
  const rawPath = utils.getRawBasePath(project.id, baseUrl, project.head);
  const api = new HttpdClient(baseUrl);

  const items: [string, IssueState][] = [
@@ -514,6 +514,7 @@
        <div slot="description">
          {#if issueState !== "read"}
            <ExtendedTextarea
+
              rawPath={rawPath(project.head)}
              enableAttachments
              body={issue.discussion[0].body}
              submitCaption="Save"
@@ -543,11 +544,7 @@
            <div class="markdown">
              <Markdown
                content={issue.discussion[0].body}
-
                rawPath={utils.getRawBasePath(
-
                  project.id,
-
                  baseUrl,
-
                  project.head,
-
                )} />
+
                rawPath={rawPath(project.head)} />
            </div>
          {/if}
          <div class="reactions">
@@ -585,7 +582,7 @@
            <ThreadComponent
              enableAttachments
              {thread}
-
              {rawPath}
+
              rawPath={rawPath(project.head)}
              canEditComment={partial(
                role.isDelegateOrAuthor,
                session?.publicKey,
@@ -599,6 +596,7 @@
      {/if}
      {#if session}
        <CommentToggleInput
+
          rawPath={rawPath(project.head)}
          placeholder="Leave your comment"
          enableAttachments
          submit={partial(createComment, session.id)} />
modified src/views/projects/Issue/New.svelte
@@ -25,6 +25,7 @@

  export let baseUrl: BaseUrl;
  export let project: Project;
+
  export let rawPath: (commit?: string) => string;
  export let tracking: boolean;

  let newEmbeds: EmbedWithOid[] = [];
@@ -191,7 +192,10 @@
              {:else if !issueText}
                <p class="txt-missing">No description</p>
              {:else}
-
                <Markdown embeds={newEmbeds} content={issueText} />
+
                <Markdown
+
                  rawPath={rawPath(project.head)}
+
                  embeds={newEmbeds}
+
                  content={issueText} />
              {/if}
            </svelte:fragment>
            <div class="author" slot="author">
modified src/views/projects/Patch.svelte
@@ -77,6 +77,7 @@

  export let baseUrl: BaseUrl;
  export let patch: Patch;
+
  export let rawPath: (commit?: string) => string;
  export let project: Project;
  export let view: PatchView;
  export let tracking: boolean;
@@ -678,6 +679,7 @@
          <div class="revision-description">
            {#if session && patchState !== "read"}
              <ExtendedTextarea
+
                rawPath={rawPath(patch.revisions[0].id)}
                body={newDescription}
                submitCaption="Save"
                submitInProgress={patchState === "submit"}
@@ -699,11 +701,7 @@
            {:else if description}
              <Markdown
                content={description}
-
                rawPath={utils.getRawBasePath(
-
                  project.id,
-
                  baseUrl,
-
                  patch.revisions[0].id,
-
                )} />
+
                rawPath={rawPath(patch.revisions[0].id)} />
            {:else}
              <span class="txt-missing">No description available</span>
            {/if}
@@ -841,6 +839,7 @@
            index > 0 ? patch.revisions[index - 1] : undefined}
          <RevisionComponent
            {baseUrl}
+
            {rawPath}
            projectId={project.id}
            {timelines}
            projectDefaultBranch={project.defaultBranch}
@@ -867,6 +866,7 @@
              {#if session && view.name === "activity"}
                <div class="connector" />
                <CommentToggleInput
+
                  rawPath={rawPath(patch.revisions[0].id)}
                  enableAttachments
                  placeholder="Leave your comment"
                  submit={partial(
modified src/views/projects/Source.svelte
@@ -3,7 +3,6 @@
  import type { BlobResult } from "./router";
  import type { Route } from "@app/lib/router";

-
  import * as utils from "@app/lib/utils";
  import { HttpdClient } from "@httpd-client";

  import Button from "@app/components/Button.svelte";
@@ -17,6 +16,7 @@
  import FilePath from "@app/components/FilePath.svelte";

  export let baseUrl: BaseUrl;
+
  export let rawPath: (commit?: string) => string;
  export let blobResult: BlobResult;
  export let branches: string[];
  export let path: string;
@@ -208,11 +208,7 @@
            {path}
            blob={blobResult.blob}
            highlighted={blobResult.highlighted}
-
            rawPath={utils.getRawBasePath(
-
              project.id,
-
              baseUrl,
-
              tree.lastCommit.id,
-
            )} />
+
            rawPath={rawPath(tree.lastCommit.id)} />
        {:else}
          <File>
            <FilePath
modified src/views/projects/router.ts
@@ -113,6 +113,7 @@ export type ProjectLoadedRoute =
        revision: string | undefined;
        tree: Tree;
        path: string;
+
        rawPath: (commit?: string) => string;
        blobResult: BlobResult;
        tracking: boolean;
      };
@@ -146,6 +147,7 @@ export type ProjectLoadedRoute =
      params: {
        baseUrl: BaseUrl;
        project: Project;
+
        rawPath: (commit?: string) => string;
        issue: Issue;
        tracking: boolean;
      };
@@ -165,6 +167,7 @@ export type ProjectLoadedRoute =
      params: {
        baseUrl: BaseUrl;
        project: Project;
+
        rawPath: (commit?: string) => string;
        tracking: boolean;
      };
    }
@@ -183,6 +186,7 @@ export type ProjectLoadedRoute =
      params: {
        baseUrl: BaseUrl;
        project: Project;
+
        rawPath: (commit?: string) => string;
        patch: Patch;
        view: PatchView;
        tracking: boolean;
@@ -263,6 +267,10 @@ export async function loadProjectRoute(
  route: ProjectRoute,
): Promise<ProjectLoadedRoute | LoadErrorRoute | NotFoundRoute> {
  const api = new HttpdClient(route.node);
+
  const rawPath = (commit?: string) =>
+
    `${route.node.scheme}://${route.node.hostname}:${route.node.port}/raw/${
+
      route.project
+
    }${commit ? `/${commit}` : ""}`;

  try {
    if (route.resource === "project.source") {
@@ -296,6 +304,7 @@ export async function loadProjectRoute(
        params: {
          baseUrl: route.node,
          project,
+
          rawPath,
          issue,
          tracking,
        },
@@ -314,6 +323,7 @@ export async function loadProjectRoute(
        params: {
          baseUrl: route.node,
          project,
+
          rawPath,
          tracking,
        },
      };
@@ -416,6 +426,10 @@ async function loadTreeView(
  route: ProjectTreeRoute,
): Promise<ProjectLoadedRoute> {
  const api = new HttpdClient(route.node);
+
  const rawPath = (commit?: string) =>
+
    `${route.node.scheme}://${route.node.hostname}:${route.node.port}/raw/${
+
      route.project
+
    }${commit ? `/${commit}` : ""}`;

  const [project, peers, branchMap, tracking] = await Promise.all([
    api.project.getById(route.project),
@@ -453,6 +467,7 @@ async function loadTreeView(
      peers,
      peer: route.peer,
      branches: Object.keys(branchMap || {}),
+
      rawPath,
      revision: route.revision,
      tree,
      path,
@@ -559,6 +574,10 @@ async function loadPatchView(
  route: ProjectPatchRoute,
): Promise<ProjectLoadedRoute> {
  const api = new HttpdClient(route.node);
+
  const rawPath = (commit?: string) =>
+
    `${route.node.scheme}://${route.node.hostname}:${route.node.port}/raw/${
+
      route.project
+
    }${commit ? `/${commit}` : ""}`;
  const [project, patch, tracking] = await Promise.all([
    api.project.getById(route.project),
    api.project.getPatchById(route.project, route.patch),
@@ -615,6 +634,7 @@ async function loadPatchView(
    params: {
      baseUrl: route.node,
      project,
+
      rawPath,
      patch,
      view,
      tracking,