Add commit detail view

Signed-off-by: Sebastian Martinez <sebastinez@me.com>
This commit is contained in:
Sebastian Martinez
2022-02-02 12:29:15 +01:00
committed by Alexis Sellier
parent 0cf6ef3427
commit 7ef1428284
11 changed files with 552 additions and 31 deletions
@@ -0,0 +1,92 @@
<script lang="ts">
import { createEventDispatcher } from "svelte";
import type { CommitStats } from "@app/commit";
import type { Diff } from "@app/diff";
import Icon from "@app/Icon.svelte";
import FileDiff from "@app/base/projects/SourceBrowser/FileDiff.svelte";
const dispatch = createEventDispatcher();
export let diff: Diff;
export let stats: CommitStats;
</script>
<style>
.changeset-summary {
margin: 1.5rem 0;
margin-left: 1rem;
}
.changeset-summary .additions {
color: var(--color-positive);
}
.changeset-summary .deletions {
color: var(--color-negative);
}
.file-header {
border: 1px solid var(--color-foreground-3);
border-radius: 0.5rem;
height: 3rem;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
background: none;
padding: 1rem;
margin-bottom: 1rem;
}
.file-header:last-child {
margin-bottom: 1rem;
}
.file-header .diff-type {
margin-left: 1rem;
padding: 0.25rem 0.5rem;
border-radius: 0.25rem;
}
.file-header .diff-type.created {
color: var(--color-positive);
background-color: var(--color-positive-1);
}
.file-header .diff-type.deleted {
color: var(--color-negative);
background-color: var(--color-negative-1);
}
.file-header .file-data {
display: flex;
flex-direction: row;
align-items: center;
}
</style>
<div class="changeset-summary">
{#if diff.modified.length > 0}
<span class="bold"> {diff.modified.length} file(s) changed </span>
with
<span class="additions bold"> {stats.additions} additions </span>
and
<span class="deletions bold"> {stats.deletions} deletions </span>
{/if}
</div>
<div>
{#each diff.created as path (path)}
<header id={path} class="file-header">
<div class="file-data">
<p class="bold">{path}</p>
<span class="diff-type created">created</span>
</div>
<Icon class="clickable" clickHandler={() => dispatch("browse", path)} name="browse" width={20} inline fill />
</header>
{/each}
{#each diff.deleted as path (path)}
<header id={path} class="file-header">
<div class="file-data">
<p class="bold">{path}</p>
<span class="diff-type deleted">deleted</span>
</div>
<Icon class="clickable" clickHandler={() => dispatch("browse", path)} name="browse" width={20} inline fill />
</header>
{/each}
</div>
{#each diff.modified as file}
<FileDiff on:browse {file} />
{/each}
@@ -0,0 +1,153 @@
<script lang="ts">
import { createEventDispatcher } from "svelte";
import Icon from "@app/Icon.svelte";
import { lineNumberL, lineNumberR, lineSign } from "@app/diff";
import type { FileDiff } from "@app/diff";
const dispatch = createEventDispatcher();
export let file: FileDiff;
function collapse() {
collapsed = !collapsed;
}
let collapsed = false;
</script>
<style>
.changeset-file {
border: 1px solid var(--color-foreground-3);
border-radius: 0.5rem;
min-width: var(--content-min-width);
margin-bottom: 2rem;
}
.changeset-file header {
cursor: pointer;
height: 3rem;
display: flex;
align-items: center;
background: none;
border-radius: 0;
padding: 1rem;
}
main {
border-top: 1px solid var(--color-foreground-3);
}
.changeset-file main {
overflow-x: auto;
}
header {
display: flex;
flex-direction: row;
justify-content: space-between;
}
header div.actions {
display: flex;
flex-direction: row;
align-items: center;
}
.binary {
padding: 1rem;
color: var(--color-foreground-level-4);
text-align: center;
background-color: var(--color-foreground-1);
}
table.diff {
font-family: var(--font-family-monospace);
table-layout: fixed;
border-collapse: collapse;
margin: 0.5rem 0;
}
tr.diff-line[data-type="+"] > * {
background: var(--color-positive-1);
}
tr.diff-line[data-type="-"] > * {
background: var(--color-negative-1);
}
td.diff-line-number {
text-align: right;
user-select: none;
line-height: 150%;
}
td.diff-line-number[data-type="+"],
td.diff-line-type[data-type="+"] {
color: var(--color-positive-6);
}
td.diff-line-number[data-type="-"],
td.diff-line-type[data-type="-"] {
color: var(--color-negative-6);
}
td.diff-line-number.left {
padding: 0 0.25rem 0 1rem;
}
td.diff-line-number.right {
padding: 0 1rem 0 0.25rem;
}
td.diff-line-content {
white-space: pre;
width: 100%;
padding-right: 0.5rem;
}
td.diff-line-type {
padding-right: 1rem;
text-align: center;
}
td.diff-expand-header {
background: var(--color-background);
color: var(--color-foreground-4);
}
td.diff-line-number {
color: var(--color-foreground-4);
}
.file-path {
margin-left: 0.5rem;
}
</style>
<article id={file.path} class="changeset-file">
<header
on:click={collapse}>
<div class="actions">
<Icon clickHandler={collapse} name="chevron" width={20} inline fill />
<p class="bold file-path">{file.path}</p>
</div>
<Icon clickHandler={() => dispatch("browse", file.path)} name="browse" width={20} inline fill />
</header>
{#if !collapsed}
<main>
{#if file.diff.type === "plain" && file.diff.hunks.length > 0}
<table class="diff">
{#each file.diff.hunks as hunk}
<tr class="diff-line">
<td colspan={2} />
<td colspan={6} class="diff-expand-header">
{hunk.header}
</td>
</tr>
{#each hunk.lines as line}
<tr class="diff-line" data-expanded data-type={lineSign(line)}>
<td
class="diff-line-number left"
data-type={lineSign(line)}>
{lineNumberL(line)}
</td>
<td
class="diff-line-number right"
data-type={lineSign(line)}>
{lineNumberR(line)}
</td>
<td class="diff-line-type" data-type={line.type}>
{lineSign(line)}
</td>
<td class="diff-line-content">{line.line}</td>
</tr>
{/each}
{/each}
</table>
{:else}
<div class="binary">Binary file</div>
{/if}
</main>
{/if}
</article>