Radish alpha
r
Radicle desktop app
Radicle
Git (anonymous pull)
Log in to clone via SSH
Extract review button
Rūdolfs Ošiņš committed 1 year ago
commit 626c4aa91428de269a7713fb5031ab1d575608f0
parent a010c04ab12372fc80ccf2df60ff13c867d83e5c
2 files changed +149 -118
added src/components/ReviewButton.svelte
@@ -0,0 +1,136 @@
+
<script lang="ts">
+
  import type { Config } from "@bindings/config/Config";
+
  import type { PatchStatus } from "@app/views/repo/router";
+
  import type { Review } from "@bindings/cob/patch/Review";
+
  import type { Revision } from "@bindings/cob/patch/Revision";
+
  import type { Verdict } from "@bindings/cob/patch/Verdict";
+

+
  import { closeFocused } from "./Popover.svelte";
+
  import { didFromPublicKey } from "@app/lib/utils";
+
  import { push } from "@app/lib/router";
+

+
  import Border from "@app/components/Border.svelte";
+
  import Icon from "@app/components/Icon.svelte";
+
  import NakedButton from "@app/components/NakedButton.svelte";
+
  import OutlineButton from "@app/components/OutlineButton.svelte";
+
  import Popover from "@app/components/Popover.svelte";
+

+
  interface Props {
+
    rid: string;
+
    patchId: string;
+
    revision: Revision;
+
    config: Config;
+
    status: PatchStatus | undefined;
+
    loadPatch: () => Promise<void>;
+
    createReview: (verdict?: Verdict) => Promise<Review | undefined>;
+
  }
+

+
  const {
+
    rid,
+
    patchId,
+
    revision,
+
    config,
+
    status,
+
    loadPatch,
+
    createReview,
+
  }: Props = $props();
+

+
  const hasOwnReview = $derived(
+
    Boolean(
+
      revision.reviews &&
+
        revision.reviews.some(
+
          value => value.author.did === didFromPublicKey(config.publicKey),
+
        ),
+
    ),
+
  );
+
</script>
+

+
<Popover popoverPositionRight="0" popoverPositionTop="2.5rem">
+
  {#snippet toggle(onclick)}
+
    <NakedButton
+
      variant="ghost"
+
      disabled={hasOwnReview}
+
      {onclick}
+
      title={hasOwnReview ? "You already published a review" : undefined}>
+
      <Icon name="add" />
+
      <span class="txt-small">Review</span>
+
    </NakedButton>
+
  {/snippet}
+

+
  {#snippet popover()}
+
    <Border
+
      variant="ghost"
+
      stylePadding="1rem"
+
      styleDisplay="flex"
+
      styleFlexDirection="column">
+
      <div class="global-flex">
+
        <OutlineButton
+
          variant="ghost"
+
          disabled={hasOwnReview}
+
          title={hasOwnReview ? "You already published a review" : undefined}
+
          onclick={async () => {
+
            const newReview = await createReview();
+
            if (newReview) {
+
              await push({
+
                resource: "repo.patch",
+
                rid,
+
                patch: patchId,
+
                status,
+
                reviewId: newReview.id,
+
              });
+
            }
+
            closeFocused();
+
          }}>
+
          <span class="global-flex" style:color="var(--color-foreground-dim)">
+
            <Icon name="comment" />
+
            <span class="txt-small">Write Review</span>
+
          </span>
+
        </OutlineButton>
+
        <OutlineButton
+
          variant="ghost"
+
          disabled={hasOwnReview}
+
          title={hasOwnReview ? "You already published a review" : undefined}
+
          onclick={async () => {
+
            await createReview("reject");
+
            await loadPatch();
+
            closeFocused();
+
          }}>
+
          <span class="global-flex" style:color="var(--color-foreground-red)">
+
            <Icon name="comment-cross" />
+
            <span class="txt-small">Reject</span>
+
          </span>
+
        </OutlineButton>
+
        <OutlineButton
+
          variant="ghost"
+
          disabled={hasOwnReview}
+
          title={hasOwnReview ? "You already published a review" : undefined}
+
          onclick={async () => {
+
            await createReview("accept");
+
            await loadPatch();
+
            closeFocused();
+
          }}>
+
          <span
+
            class="global-flex"
+
            style:color="var(--color-foreground-success)">
+
            <Icon name="comment-checkmark" />
+
            <span class="txt-small">Accept</span>
+
            <span></span>
+
          </span>
+
        </OutlineButton>
+
      </div>
+

+
      <div
+
        class="txt-small txt-missing global-flex"
+
        style:margin-top="0.5rem"
+
        style:align-items="flex-start">
+
        <div style:padding-top="3px"><Icon name="info" /></div>
+
        <div>
+
          Clicking the buttons will create a blank review, add comments, a
+
          summary, and your verdict after. Depending on your sync settings your
+
          review might be published to the network right away. We are actively
+
          working on draft reviews, stay tuned.
+
        </div>
+
      </div>
+
    </Border>
+
  {/snippet}
+
</Popover>
modified src/components/Reviews.svelte
@@ -6,43 +6,29 @@
  import type { Verdict } from "@bindings/cob/patch/Verdict";

  import { announce } from "@app/components/AnnounceSwitch.svelte";
-
  import { closeFocused } from "./Popover.svelte";
-
  import { didFromPublicKey } from "@app/lib/utils";
  import { invoke } from "@app/lib/invoke";
  import { nodeRunning } from "@app/lib/events";
-
  import { push } from "@app/lib/router";

-
  import Border from "@app/components/Border.svelte";
  import Icon from "@app/components/Icon.svelte";
  import NakedButton from "@app/components/NakedButton.svelte";
-
  import OutlineButton from "@app/components/OutlineButton.svelte";
-
  import Popover from "@app/components/Popover.svelte";
+
  import ReviewButton from "@app/components/ReviewButton.svelte";
  import ReviewTeaser from "@app/components/ReviewTeaser.svelte";

  interface Props {
-
    rid: string;
+
    config: Config;
+
    loadPatch: () => Promise<void>;
    patchId: string;
    revision: Revision;
-
    config: Config;
+
    rid: string;
    status: PatchStatus | undefined;
-
    loadPatch: () => Promise<void>;
  }

-
  const { rid, patchId, revision, config, status, loadPatch }: Props = $props();
+
  const { config, loadPatch, patchId, revision, rid, status }: Props = $props();

  let hideReviews = $state(
    revision.reviews === undefined || revision.reviews.length === 0,
  );

-
  const hasOwnReview = $derived(
-
    Boolean(
-
      revision.reviews &&
-
        revision.reviews.some(
-
          value => value.author.did === didFromPublicKey(config.publicKey),
-
        ),
-
    ),
-
  );
-

  $effect(() => {
    // eslint-disable-next-line @typescript-eslint/no-unused-expressions
    patchId;
@@ -96,105 +82,14 @@
    </NakedButton>

    <div class="global-flex" style:margin-left="auto">
-
      <Popover popoverPositionRight="0" popoverPositionTop="2.5rem">
-
        {#snippet toggle(onclick)}
-
          <NakedButton
-
            variant="ghost"
-
            disabled={hasOwnReview}
-
            {onclick}
-
            title={hasOwnReview ? "You already published a review" : undefined}>
-
            <Icon name="add" />
-
            <span class="txt-small">Review</span>
-
          </NakedButton>
-
        {/snippet}
-

-
        {#snippet popover()}
-
          <Border
-
            variant="ghost"
-
            stylePadding="1rem"
-
            styleDisplay="flex"
-
            styleFlexDirection="column">
-
            <div class="global-flex">
-
              <OutlineButton
-
                variant="ghost"
-
                disabled={hasOwnReview}
-
                title={hasOwnReview
-
                  ? "You already published a review"
-
                  : undefined}
-
                onclick={async () => {
-
                  const newReview = await createReview();
-
                  if (newReview) {
-
                    await push({
-
                      resource: "repo.patch",
-
                      rid,
-
                      patch: patchId,
-
                      status,
-
                      reviewId: newReview.id,
-
                    });
-
                  }
-
                  closeFocused();
-
                }}>
-
                <span
-
                  class="global-flex"
-
                  style:color="var(--color-foreground-dim)">
-
                  <Icon name="comment" />
-
                  <span class="txt-small">Write Review</span>
-
                </span>
-
              </OutlineButton>
-
              <OutlineButton
-
                variant="ghost"
-
                disabled={hasOwnReview}
-
                title={hasOwnReview
-
                  ? "You already published a review"
-
                  : undefined}
-
                onclick={async () => {
-
                  await createReview("reject");
-
                  await loadPatch();
-
                  closeFocused();
-
                }}>
-
                <span
-
                  class="global-flex"
-
                  style:color="var(--color-foreground-red)">
-
                  <Icon name="comment-cross" />
-
                  <span class="txt-small">Reject</span>
-
                </span>
-
              </OutlineButton>
-
              <OutlineButton
-
                variant="ghost"
-
                disabled={hasOwnReview}
-
                title={hasOwnReview
-
                  ? "You already published a review"
-
                  : undefined}
-
                onclick={async () => {
-
                  await createReview("accept");
-
                  await loadPatch();
-
                  closeFocused();
-
                }}>
-
                <span
-
                  class="global-flex"
-
                  style:color="var(--color-foreground-success)">
-
                  <Icon name="comment-checkmark" />
-
                  <span class="txt-small">Accept</span>
-
                  <span></span>
-
                </span>
-
              </OutlineButton>
-
            </div>
-

-
            <div
-
              class="txt-small txt-missing global-flex"
-
              style:margin-top="0.5rem"
-
              style:align-items="flex-start">
-
              <div style:padding-top="3px"><Icon name="info" /></div>
-
              <div>
-
                Clicking the buttons will create a blank review, add comments, a
-
                summary, and your verdict after. Depending on your sync settings
-
                your review might be published to the network right away. We are
-
                actively working on draft reviews, stay tuned.
-
              </div>
-
            </div>
-
          </Border>
-
        {/snippet}
-
      </Popover>
+
      <ReviewButton
+
        {rid}
+
        {patchId}
+
        {revision}
+
        {config}
+
        {status}
+
        {loadPatch}
+
        {createReview} />
    </div>
  </div>