Skip to content

Commit

Permalink
feat: stage/unstage directory
Browse files Browse the repository at this point in the history
close #
  • Loading branch information
Vinzent03 committed Sep 30, 2022
1 parent 06f3c22 commit 61b3eb3
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 73 deletions.
3 changes: 2 additions & 1 deletion src/gitManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,11 @@ export abstract class GitManager {
childrenWithSameTitle.forEach((item) => children.remove(item));
list.push({
title: title,
path: first.path,
children: this.getTreeStructure(childrenWithSameTitle, (beginLength > 0 ? (beginLength + title.length) : title.length) + 1)
});
} else {
list.push({ title: restPath, statusResult: first });
list.push({ title: restPath, statusResult: first, path: first.path });
children.remove(first);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export interface BranchInfo {

export interface TreeItem {
title: string;
path: string;
statusResult?: FileStatusResult;
children?: TreeItem[];
}
Expand Down
7 changes: 5 additions & 2 deletions src/ui/sidebar/components/fileComponent.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@

<style lang="scss">
main {
.nav-file-title-content {
display: flex;
align-items: center;
}
.tools {
display: flex;
margin-left: auto;
Expand All @@ -150,8 +154,7 @@
.buttons {
display: flex;
> * {
padding: var(--size-2-1) var(--size-2-1);
border-radius: var(--clickable-icon-radius);
padding: 0 0;
height: auto;
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/ui/sidebar/components/pulledFileComponent.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@

<style lang="scss">
main {
.nav-file-title-content {
display: flex;
align-items: center;
}
.tools {
display: flex;
margin-left: auto;
Expand Down
41 changes: 23 additions & 18 deletions src/ui/sidebar/components/stagedFileComponent.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
aria-label={formattedPath.split("/").last() != formattedPath
? formattedPath
: ""}
on:click={showDiff}
on:click|self={showDiff}
>
<div class="nav-file-title-content">
{formattedPath.split("/").last()?.replace(".md", "")}
Expand Down Expand Up @@ -96,27 +96,32 @@
</main>

<style lang="scss">
.tools {
display: flex;
margin-left: auto;
.type {
padding-left: var(--size-2-1);
main {
.nav-file-title-content {
display: flex;
align-items: center;
justify-content: center;
&[data-type="M"] {
color: orange;
}
&[data-type="D"] {
color: red;
}
}
.buttons {
.tools {
display: flex;
> * {
padding: var(--size-2-1) var(--size-2-1);
border-radius: var(--clickable-icon-radius);
height: auto;
margin-left: auto;
.type {
padding-left: var(--size-2-1);
display: flex;
align-items: center;
justify-content: center;
&[data-type="M"] {
color: orange;
}
&[data-type="D"] {
color: red;
}
}
.buttons {
display: flex;
> * {
padding: 0 0;
height: auto;
}
}
}
}
Expand Down
158 changes: 106 additions & 52 deletions src/ui/sidebar/components/treeComponent.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,24 @@
export let view: GitView;
export let fileType: FileType;
export let topLevel = false;
const closed: Record<string, boolean> = {};
function stage(path: string) {
plugin.gitManager.stageAll({ dir: path }).finally(() => {
dispatchEvent(new CustomEvent("git-refresh"));
});
}
function unstage(path: string) {
plugin.gitManager.unstageAll({ dir: path }).finally(() => {
dispatchEvent(new CustomEvent("git-refresh"));
});
}
</script>

<main class:topLevel>
{#each hierarchy.children as entity}
{#if entity.statusResult}
<div class="file-view">
<div>
{#if fileType == FileType.staged}
<StagedFileComponent
change={entity.statusResult}
Expand All @@ -39,29 +49,86 @@
{:else}
<div class="nav-folder" class:is-collapsed={closed[entity.title]}>
<div
on:click={() =>
class="nav-folder-title"
on:click|self={() =>
(closed[entity.title] = !closed[entity.title])}
>
<div class="nav-folder-title">
<div
class="nav-folder-collapse-indicator collapse-icon"
<div class="nav-folder-collapse-indicator collapse-icon">
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="svg-icon right-triangle"
><path d="M3 8L12 17L21 8" /></svg
>
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="svg-icon right-triangle"
><path d="M3 8L12 17L21 8" /></svg
>
</div>
<div class="nav-folder-title-content">
{entity.title}
</div>
<div class="nav-folder-title-content">
{entity.title}
</div>
<div class="tools">
<div class="buttons">
{#if fileType == FileType.staged}
<div
data-icon="minus"
aria-label="Unstage"
on:click={() => unstage(entity.title)}
class="clickable-icon"
>
<svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="svg-icon lucide-minus"
><line
x1="5"
y1="12"
x2="19"
y2="12"
/></svg
>
</div>
{:else}
<div
data-icon="plus"
aria-label="Stage"
on:click={() => stage(entity.path)}
class="clickable-icon"
>
<svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class="svg-icon lucide-plus"
><line
x1="12"
y1="5"
x2="12"
y2="19"
/><line
x1="5"
y1="12"
x2="19"
y2="12"
/></svg
>
</div>
{/if}
</div>
</div>
</div>
Expand All @@ -85,34 +152,21 @@
</main>

<style lang="scss">
// main:not(.topLevel) {
// margin-left: 5px;
// }
// .opener {
// display: flex;
// justify-content: space-between;
// align-items: center;
// padding: 0 4px;
// .collapse-icon::after {
// content: "\00a0";
// }
// div {
// display: flex;
// }
// svg {
// transform: rotate(-90deg);
// }
// &.open svg {
// transform: rotate(0);
// }
// span {
// font-size: 0.8rem;
// }
// }
// .file-view {
// margin-left: 9px;
// }
main {
.nav-folder-title-content {
display: flex;
align-items: center;
}
.tools {
display: flex;
margin-left: auto;
.buttons {
display: flex;
> * {
padding: 0 0;
height: auto;
}
}
}
}
</style>

0 comments on commit 61b3eb3

Please sign in to comment.