Skip to content

Commit

Permalink
Add menu to create a new file
Browse files Browse the repository at this point in the history
  • Loading branch information
G4brym committed May 17, 2024
1 parent 39ba4a0 commit d4a5bc5
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 1 deletion.
91 changes: 91 additions & 0 deletions packages/dashboard/src/components/files/CreateFile.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<template>
<q-dialog v-model="modal" @hide="cancel">
<q-card style="min-width: 350px">
<q-form
@submit="onSubmit"
>
<q-card-section>
<div class="text-h6">New File Name</div>
</q-card-section>

<q-card-section class="q-pt-none">
<q-input dense v-model="newFileName" autofocus
lazy-rules
:rules="[ val => val && val.length > 0 || 'Please type something']" />
</q-card-section>

<q-card-actions align="right" class="text-primary">
<q-btn flat label="Cancel" v-close-popup />
<q-btn flat label="Create" type="submit" :loading="loading" />
</q-card-actions>
</q-form>
</q-card>
</q-dialog>
</template>

<script>
import { defineComponent } from "vue";
import { useMainStore } from "stores/main-store";
import { apiHandler, decode, encode, ROOT_FOLDER } from "src/appUtils";
export default defineComponent({
name: "CreateFile",
data: function() {
return {
modal: false,
newFileName: "",
loading: false
};
},
methods: {
cancel: function() {
this.modal = false;
this.newFileName = "";
this.loading = false
},
onSubmit: async function() {
this.loading = true
const newFile = new Blob([''], {type: 'text/plain'});
await apiHandler.uploadObjects(newFile, this.selectedFolder + this.newFileName, this.selectedBucket);
this.$bus.emit("fetchFiles");
// TODO: open the new file in preview and edit mode
// await this.$router.push({
// name: "files-file",
// params: {
// bucket: this.$route.params.bucket,
// folder: this.$route.params.folder || ROOT_FOLDER,
// file: encode(this.newFileName)
// }
// });
this.loading = false
this.modal = false;
this.newFileName = "";
},
open: function() {
this.modal = true;
}
},
computed: {
selectedBucket: function() {
return this.$route.params.bucket;
},
selectedFolder: function() {
if (this.$route.params.folder && this.$route.params.folder !== ROOT_FOLDER) {
return decode(this.$route.params.folder);
}
return "";
}
},
setup() {
const mainStore = useMainStore();
return {
mainStore
};
}
});
</script>
12 changes: 11 additions & 1 deletion packages/dashboard/src/components/main/LeftSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
<q-btn color="green" icon="add" stack class="q-mb-lg" label="New">
<q-menu>
<q-list>
<q-item clickable v-close-popup @click="$refs.createFile.open()">
<q-item-section>
<q-item-label>
<q-icon name="note_add" size="sm" />
New File
</q-item-label>
</q-item-section>
</q-item>
<q-item clickable v-close-popup @click="$refs.createFolder.open()">
<q-item-section>
<q-item-label>
Expand Down Expand Up @@ -102,12 +110,14 @@
</q-dialog>

<create-folder ref="createFolder" />
<create-file ref="createFile" />
</template>

<script>
import { defineComponent } from "vue";
import { useMainStore } from "stores/main-store";
import CreateFolder from "components/files/CreateFolder.vue";
import CreateFile from "components/files/CreateFile.vue";
export default defineComponent({
name: "LeftSidebar",
Expand All @@ -117,7 +127,7 @@ export default defineComponent({
settingsPopup: false
};
},
components: { CreateFolder },
components: { CreateFolder, CreateFile },
methods: {
gotoEmail: function() {
if (this.selectedApp !== "email")
Expand Down

0 comments on commit d4a5bc5

Please sign in to comment.