Skip to content

Commit

Permalink
Add checkout
Browse files Browse the repository at this point in the history
  • Loading branch information
hateofhades committed Dec 26, 2024
1 parent 6d93136 commit aa6af38
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 5 deletions.
5 changes: 4 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Tauri + Vue + Typescript App</title>
<title>BranchWise</title>
<script>
document.addEventListener('contextmenu', event => event.preventDefault());
</script>
</head>

<body>
Expand Down
4 changes: 3 additions & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use database::storage::DATABASE;
use errors::git_error::GitErrorProject;
use git::project_folder::{
get_commit_history, get_database_projects, open_git_project, remove_database_project,
set_current_project,
set_current_project, checkout_branch, checkout_commit
};
use tauri::{AppHandle, Emitter, Manager};

Expand Down Expand Up @@ -89,6 +89,8 @@ fn main() {
remove_database_project,
set_current_project,
get_commit_history,
checkout_branch,
checkout_commit
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
Expand Down
5 changes: 4 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
{{ snackbar.text }}
</v-snackbar>
<DialogComponent />
<ContextMenu />

Check warning on line 16 in src/App.vue

View workflow job for this annotation

GitHub Actions / Lint And Build

Expected " " character, but found "\t" character
</v-app>
</template>

<script lang="ts">
import DialogComponent from "@/components/DialogComponent.vue";
import ContextMenu from "@/components/Dialogs/ContextMenu.vue";
import SidebarComponent from "@/components/SidebarComponent.vue";
import TopbarComponent from "@/components/TopbarComponent.vue";
import { registerListeners, unregisterListeners } from "@/listeners";
Expand All @@ -35,7 +37,8 @@ export default defineComponent({
components: {
SidebarComponent,
TopbarComponent,
DialogComponent
DialogComponent,
ContextMenu
},
data() {
return {
Expand Down
53 changes: 53 additions & 0 deletions src/components/Dialogs/ContextMenu.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<template>
<v-menu :model-value="isShowing" :target="[posX, posY]" v-on:update:model-value="closeMenu">

Check warning on line 2 in src/components/Dialogs/ContextMenu.vue

View workflow job for this annotation

GitHub Actions / Lint And Build

Expected indentation of 2 spaces but found 4 spaces

Check warning on line 2 in src/components/Dialogs/ContextMenu.vue

View workflow job for this annotation

GitHub Actions / Lint And Build

':target' should be on a new line

Check warning on line 2 in src/components/Dialogs/ContextMenu.vue

View workflow job for this annotation

GitHub Actions / Lint And Build

'v-on:update:model-value' should be on a new line

Check warning on line 2 in src/components/Dialogs/ContextMenu.vue

View workflow job for this annotation

GitHub Actions / Lint And Build

Expected '@' instead of 'v-on:'
<v-list>

Check warning on line 3 in src/components/Dialogs/ContextMenu.vue

View workflow job for this annotation

GitHub Actions / Lint And Build

Expected indentation of 4 spaces but found 6 spaces
<v-list-item

Check warning on line 4 in src/components/Dialogs/ContextMenu.vue

View workflow job for this annotation

GitHub Actions / Lint And Build

Expected indentation of 6 spaces but found 8 spaces

Check warning on line 4 in src/components/Dialogs/ContextMenu.vue

View workflow job for this annotation

GitHub Actions / Lint And Build

Expected no line breaks before closing bracket, but 1 line break found
>

Check warning on line 5 in src/components/Dialogs/ContextMenu.vue

View workflow job for this annotation

GitHub Actions / Lint And Build

Expected indentation of 6 spaces but found 8 spaces
<v-list-item-title @click="checkout">Checkout</v-list-item-title>

Check warning on line 6 in src/components/Dialogs/ContextMenu.vue

View workflow job for this annotation

GitHub Actions / Lint And Build

Expected indentation of 8 spaces but found 10 spaces
</v-list-item>
</v-list>
</v-menu>
</template>

<script lang="ts">
import { useDialogStore } from '@/stores/dialogs';

Check failure on line 13 in src/components/Dialogs/ContextMenu.vue

View workflow job for this annotation

GitHub Actions / Lint And Build

Strings must use doublequote
import { useProjectStore } from '@/stores/project';

Check failure on line 14 in src/components/Dialogs/ContextMenu.vue

View workflow job for this annotation

GitHub Actions / Lint And Build

Strings must use doublequote
import { TauriCommands } from '@/types/tauri';

Check failure on line 15 in src/components/Dialogs/ContextMenu.vue

View workflow job for this annotation

GitHub Actions / Lint And Build

Strings must use doublequote
import { invoke } from '@tauri-apps/api/core';

Check failure on line 16 in src/components/Dialogs/ContextMenu.vue

View workflow job for this annotation

GitHub Actions / Lint And Build

Strings must use doublequote
import { mapState } from 'pinia';

Check failure on line 17 in src/components/Dialogs/ContextMenu.vue

View workflow job for this annotation

GitHub Actions / Lint And Build

Strings must use doublequote
import { defineComponent } from 'vue';

Check failure on line 18 in src/components/Dialogs/ContextMenu.vue

View workflow job for this annotation

GitHub Actions / Lint And Build

Strings must use doublequote
export default defineComponent({
name: "ContextMenu",

Check failure on line 21 in src/components/Dialogs/ContextMenu.vue

View workflow job for this annotation

GitHub Actions / Lint And Build

Expected indentation of 1 tab but found 4 spaces
computed: {

Check failure on line 22 in src/components/Dialogs/ContextMenu.vue

View workflow job for this annotation

GitHub Actions / Lint And Build

Expected indentation of 1 tab but found 4 spaces
isShowing: {
get() {
return this.contextMenu.isOpen;
},
set(value: boolean) {
if (value === false) {
useDialogStore().closeContextMenu();
}
}
},
posX() {

Check failure on line 33 in src/components/Dialogs/ContextMenu.vue

View workflow job for this annotation

GitHub Actions / Lint And Build

Expected indentation of 2 tabs but found 8 spaces
return useDialogStore().contextMenu.position.x;

Check failure on line 34 in src/components/Dialogs/ContextMenu.vue

View workflow job for this annotation

GitHub Actions / Lint And Build

Expected indentation of 3 tabs but found 12 spaces
},
posY() {
return useDialogStore().contextMenu.position.y;
},
...mapState(useDialogStore, ["contextMenu"])
},
methods: {
closeMenu() {
useDialogStore().closeContextMenu();
},
checkout() {
invoke(TauriCommands.CheckoutCommit, {
project: useProjectStore().getSelectedProject,
hash: useDialogStore().contextMenu.commitHash
});
}
}
});
</script>
7 changes: 6 additions & 1 deletion src/components/Project/Commit/CommitListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
style="height: 10vh;"
:class="commitClass"
@click="setCommit"
@click.right="showContextMenu"
>
<v-col
style="height: 85%;"
Expand Down Expand Up @@ -50,6 +51,7 @@
</template>

<script lang="ts">
import { useDialogStore } from "@/stores/dialogs";
import { useProjectStore } from "@/stores/project";
import { getAuthorDate } from "@/types/gitAuthor";
import { getHash, IGitCommit } from "@/types/gitCommit";
Expand Down Expand Up @@ -93,7 +95,10 @@ export default defineComponent({
methods: {
setCommit() {
useProjectStore().setCommit(this.commit.hash);
}
},
showContextMenu(event: MouseEvent) {
useDialogStore().showContextMenu(getHash(this.commit), event.clientX, event.clientY);
}
}
});
</script>
Expand Down
30 changes: 29 additions & 1 deletion src/stores/dialogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ interface IDialogState {
title: string;
message: string;
onConfirm: () => void;
}
},
contextMenu: {
isOpen: boolean;
commitHash: string;
position: {
x: number;
y: number;
};
}
}

export const useDialogStore = defineStore("dialog", {
Expand All @@ -30,6 +38,13 @@ export const useDialogStore = defineStore("dialog", {
title: "",
message: "",
onConfirm: () => { return; }
},
contextMenu: {

Check failure on line 42 in src/stores/dialogs.ts

View workflow job for this annotation

GitHub Actions / Coverage

Property 'commitHash' is missing in type '{ isOpen: false; position: { x: number; y: number; }; }' but required in type '{ isOpen: boolean; commitHash: string; position: { x: number; y: number; }; }'.

Check failure on line 42 in src/stores/dialogs.ts

View workflow job for this annotation

GitHub Actions / Lint

Property 'commitHash' is missing in type '{ isOpen: false; position: { x: number; y: number; }; }' but required in type '{ isOpen: boolean; commitHash: string; position: { x: number; y: number; }; }'.
isOpen: false,
position: {
x: 0,
y: 0
}
}
}),
actions: {
Expand Down Expand Up @@ -57,6 +72,19 @@ export const useDialogStore = defineStore("dialog", {
},
closeConfirmationDialog() {
this.confirmationDialog.isOpen = false;
},
showContextMenu(hash: string, x: number, y: number) {
this.contextMenu = {
position: {
x,
y
},
commitHash: hash,
isOpen: true
};
},
closeContextMenu() {
this.contextMenu.isOpen = false;
}
}
});
2 changes: 2 additions & 0 deletions src/types/tauri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export enum TauriCommands {
RemoveDatabaseProject = "remove_database_project",
SetCurrentBranch = "set_current_branch",
SetCurrentProject = "set_current_project",
CheckoutBranch = "checkout_branch",
CheckoutCommit = "checkout_commit",
}

export enum TauriListen {
Expand Down

0 comments on commit aa6af38

Please # to comment.