Organise files more consistently

Signed-off-by: Rūdolfs Ošiņš <rudolfs@osins.org>
This commit is contained in:
Rūdolfs Ošiņš
2022-12-22 16:46:08 +01:00
parent e86accafae
commit caa83db480
130 changed files with 720 additions and 707 deletions
@@ -0,0 +1,54 @@
<script lang="ts">
import type { Patch } from "@app/lib/patch";
export let patch: Patch;
</script>
<style>
.metadata {
flex-basis: 18rem;
margin-left: 1rem;
border-radius: var(--border-radius-medium);
font-size: var(--font-size-small);
padding-left: 1rem;
}
.metadata-section {
margin-bottom: 1rem;
border-bottom: 1px dashed var(--color-foreground-4);
}
.metadata-section-header {
font-size: var(--font-size-small);
margin-bottom: 0.75rem;
color: var(--color-foreground-5);
}
.metadata-section-body {
margin-bottom: 1.25rem;
}
.metadata-section-empty {
color: var(--color-foreground-6);
}
.label {
border-radius: var(--border-radius);
color: var(--color-tertiary);
background-color: var(--color-tertiary-2);
padding: 0.25rem 0.75rem;
margin-right: 0.5rem;
font-size: var(--font-size-small);
line-height: 1.6;
}
</style>
<div class="metadata layout-desktop">
<div class="metadata-section">
<div class="metadata-section-header">Labels</div>
<div class="metadata-section-body">
{#if patch.labels?.length}
{#each patch.labels as label}
<span class="label">{label}</span>
{/each}
{:else}
<div class="metadata-section-empty">No labels.</div>
{/if}
</div>
</div>
</div>
+102
View File
@@ -0,0 +1,102 @@
<script lang="ts" strictEvents>
import type { ToggleButtonOption } from "@app/components/ToggleButton.svelte";
import Dropdown from "@app/components/Dropdown.svelte";
import Floating, { closeFocused } from "@app/components/Floating.svelte";
import ToggleButton from "@app/components/ToggleButton.svelte";
import type { Revision } from "@app/lib/patch";
import { PatchTab } from "@app/lib/patch";
import { formatCommit, formatTimestamp } from "@app/lib/utils";
import { createEventDispatcher } from "svelte";
export let revisions: Revision[];
export let revisionNumber: number;
export let activeTab: PatchTab;
const dispatch = createEventDispatcher<{
switchTab: PatchTab;
revisionChanged: string;
}>();
const formatRevisionName = (revision: Revision, index: number) => {
return `R${index} ${formatCommit(revision.oid)} ${formatTimestamp(
revision.timestamp,
)}`;
};
const revisionList = Object.values(revisions).map((b, i) => ({
key: formatRevisionName(b, i),
value: i.toString(),
title: `Browse revision ${formatRevisionName(b, i)}`,
badge: null,
}));
const onRevisionChange = ({ detail }: { detail: string }) => {
closeFocused();
dispatch("revisionChanged", detail);
};
let options: ToggleButtonOption<PatchTab>[];
$: options = [
{
title: "Patch",
value: PatchTab.Timeline,
},
{
title: "Changeset",
value: PatchTab.Diff,
},
];
</script>
<style>
.bar {
align-items: center;
display: flex;
gap: 1rem;
margin: 1.5rem 0;
}
.revision-toggle {
border-radius: var(--border-radius-small);
border: none;
color: var(--color-foreground-6);
font-family: var(--font-family-monospace);
font-size: var(--font-size-tiny);
height: var(--button-tiny-height);
padding: 0.25rem 0.5rem;
background-color: var(--color-background);
}
.revision-toggle:hover {
background-color: var(--color-foreground-1);
color: var(--color-foreground);
}
.revision-toggle:disabled {
color: var(--color-foreground-5);
}
</style>
<div class="bar txt-small">
<ToggleButton
{options}
on:select={e => {
dispatch("switchTab", e.detail);
}}
active={activeTab} />
<Floating disabled={revisions.length <= 1}>
<button
slot="toggle"
class="txt-small revision-toggle"
disabled={revisions.length <= 1}>
{formatRevisionName(revisions[revisionNumber], revisionNumber)}
</button>
<svelte:fragment slot="modal">
<Dropdown
items={revisionList}
selected={revisionNumber.toString()}
on:select={onRevisionChange} />
</svelte:fragment>
</Floating>
</div>
+132
View File
@@ -0,0 +1,132 @@
<script lang="ts">
import type { Patch } from "@app/lib/patch";
import type { Wallet } from "@app/lib/wallet";
import { Profile, ProfileType } from "@app/lib/profile";
import { formatObjectId } from "@app/lib/cobs";
import { onMount } from "svelte";
import { twemoji } from "@app/lib/utils";
import Authorship from "@app/components/Authorship.svelte";
export let patch: Patch;
export let wallet: Wallet;
let profile: Profile | null = null;
onMount(async () => {
if (patch.author.profile?.ens?.name) {
profile = await Profile.get(
patch.author.profile.ens.name,
ProfileType.Minimal,
wallet,
);
}
});
const commentCount = patch.countComments(patch.revisions.length - 1);
</script>
<style>
.patch-teaser {
display: flex;
align-items: center;
justify-content: space-between;
background-color: var(--color-foreground-1);
padding: 0.75rem 0;
}
.patch-teaser:hover {
background-color: var(--color-foreground-2);
cursor: pointer;
}
.patch-id {
color: var(--color-foreground-5);
font-size: var(--font-size-tiny);
font-family: var(--font-family-monospace);
margin-left: 0.5rem;
}
.column-left {
flex: min-content;
}
.column-right {
display: flex;
align-items: center;
justify-content: flex-end;
margin-right: 1rem;
flex-basis: 5rem;
}
.comment-count {
color: var(--color-foreground-4);
font-weight: var(--font-weight-bold);
}
.comment-count .emoji {
margin-right: 0.25rem;
}
.state {
padding: 0 1rem;
}
.state-icon {
width: 0.5rem;
height: 0.5rem;
border-radius: 0.5rem;
}
.open {
background-color: var(--color-positive);
}
.closed {
background-color: var(--color-negative);
}
.summary {
display: flex;
flex-direction: row;
align-items: center;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
padding-right: 1rem;
}
@media (max-width: 720px) {
.column-left {
overflow: hidden;
}
.summary {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
padding-right: 1rem;
}
}
</style>
<div class="patch-teaser">
<div class="state">
<div
class="state-icon"
class:closed={patch.state === "archived"}
class:open={patch.state === "proposed"} />
</div>
<div class="column-left">
<div class="summary">
<!-- TODO: Truncation not working on overflow -->
{patch.title}
<span class="patch-id">{formatObjectId(patch.id)}</span>
</div>
<Authorship
{profile}
{wallet}
caption="opened"
author={patch.author}
timestamp={patch.timestamp} />
</div>
{#if commentCount > 0}
<div class="column-right">
<div class="comment-count">
<span class="txt-tiny emoji" use:twemoji>💬</span>
<span>{commentCount}</span>
</div>
</div>
{/if}
</div>
@@ -0,0 +1,77 @@
<script lang="ts">
import type { Wallet } from "@app/lib/wallet";
import { type Patch, TimelineType } from "@app/lib/patch";
import { formatSeedId } from "@app/lib/utils";
import { canonicalize } from "@app/lib/utils";
import Comment from "@app/components/Comment.svelte";
import type { Blob, Project } from "@app/lib/project";
import Authorship from "@app/components/Authorship.svelte";
import Review from "@app/views/projects/Patch/Review.svelte";
export let patch: Patch;
export let revisionNumber: number;
export let wallet: Wallet;
export let project: Project;
$: timeline = patch.createTimeline(revisionNumber);
// Get an image blob based on a relative path.
const getImage = async (imagePath: string): Promise<Blob> => {
const finalPath = canonicalize(imagePath, "/"); // We only use the root path in issues.
const commit = project.branches[project.defaultBranch]; // We suppose that all issues are only looked at on HEAD of the default branch.
return project.getBlob(commit, finalPath);
};
</script>
<style>
.timeline {
display: flex;
flex-direction: column;
flex: 1;
}
.replies {
margin-left: 2rem;
}
.element {
margin: 0 0 1rem 3rem;
}
</style>
<div class="timeline">
{#each timeline as element}
{#if element.type === TimelineType.Merge && element.inner.peer.person}
<div class="element">
<Authorship
author={{
peer: element.inner.peer.id,
urn: element.inner.peer.person.urn,
profile: element.inner.peer.person,
}}
caption={`merged to ${formatSeedId(element.inner.peer.id)}`}
timestamp={element.timestamp}
{wallet} />
</div>
{:else if element.type === TimelineType.Review && element.inner.author.profile?.ens?.name}
<div class="margin-left">
<Review review={element.inner} {wallet} {getImage} />
</div>
{:else if element.type === TimelineType.Comment}
<div class="margin-left">
<!-- Since the element variable only experiences changes on the inner property,
this component has to be forced to be rerendered when element.inner changes -->
{#key element.inner}
<Comment comment={element.inner} {wallet} {getImage} />
{/key}
</div>
{:else if element.type === TimelineType.Thread}
<div class="margin-left">
<Comment comment={element.inner} {wallet} {getImage} />
<div class="replies">
{#each element.inner.replies as comment}
<Comment caption="replied" {comment} {wallet} {getImage} />
{/each}
</div>
</div>
{/if}
{/each}
</div>
+50
View File
@@ -0,0 +1,50 @@
<script lang="ts">
import { onMount } from "svelte";
import type { Wallet } from "@app/lib/wallet";
import type { Review } from "@app/lib/patch";
import { formatVerdict } from "@app/lib/patch";
import type { Blob } from "@app/lib/project";
import { Profile, ProfileType } from "@app/lib/profile";
import Authorship from "@app/components/Authorship.svelte";
import Comment from "@app/components/Comment.svelte";
export let review: Review;
export let wallet: Wallet;
export let getImage: (path: string) => Promise<Blob>;
let profile: Profile | null = null;
onMount(async () => {
if (review.author.profile?.ens?.name) {
profile = await Profile.get(
review.author.profile.ens.name,
ProfileType.Minimal,
wallet,
);
}
});
</script>
<style>
div {
margin: 0 0 1rem 3rem;
}
</style>
{#if review.comment.body}
<Comment
{wallet}
{getImage}
comment={review.comment}
caption={formatVerdict(review.verdict)} />
{:else}
<div>
<Authorship
{wallet}
{profile}
author={review.author}
timestamp={review.timestamp}
caption={formatVerdict(review.verdict)} />
</div>
{/if}