|
| 1 | +<template> |
| 2 | + <div class="flex items-center mb-12"> |
| 3 | + <h2 class="text-2xl font-semibold">Projects</h2> |
| 4 | + <div class="flex-grow"></div> |
| 5 | + <ui-input placeholder="Search" prepend-icon="mdi-magnify"></ui-input> |
| 6 | + <ui-button icon class="ml-2"> |
| 7 | + <v-mdi name="mdi-filter-outline"></v-mdi> |
| 8 | + </ui-button> |
| 9 | + <ui-button variant="primary" class="ml-2" @click="projectModal.show = true"> |
| 10 | + <v-mdi name="mdi-plus" class="mr-1 -ml-2"></v-mdi> |
| 11 | + Project |
| 12 | + </ui-button> |
| 13 | + <ui-modal v-model="projectModal.show" content-class="max-w-md"> |
| 14 | + <template #header> |
| 15 | + <p>Import Project</p> |
| 16 | + </template> |
| 17 | + <div class="flex items-end"> |
| 18 | + <ui-input |
| 19 | + label="Select a folder" |
| 20 | + readonly |
| 21 | + class="flex-1 mr-2" |
| 22 | + placeholder="No folder selected" |
| 23 | + :model-value="projectModal.path" |
| 24 | + @click="selectDirectory" |
| 25 | + ></ui-input> |
| 26 | + <ui-button icon @click="selectDirectory"> |
| 27 | + <v-mdi name="mdi-folder-open-outline"></v-mdi> |
| 28 | + </ui-button> |
| 29 | + </div> |
| 30 | + <form class="mt-4" @submit.prevent="importProject"> |
| 31 | + <ui-input |
| 32 | + label="Project name" |
| 33 | + placeholder="Name" |
| 34 | + v-model="projectModal.name" |
| 35 | + class="w-full" |
| 36 | + ></ui-input> |
| 37 | + <ui-button |
| 38 | + class="w-full mt-12" |
| 39 | + variant="primary" |
| 40 | + :disabled="!projectModal.name || !projectModal.path" |
| 41 | + > |
| 42 | + Import Project |
| 43 | + </ui-button> |
| 44 | + </form> |
| 45 | + </ui-modal> |
| 46 | + </div> |
| 47 | +</template> |
| 48 | +<script> |
| 49 | +import { shallowReactive } from 'vue'; |
| 50 | +import { useStore } from 'vuex'; |
| 51 | +import { useToast } from 'vue-toastification'; |
| 52 | +
|
| 53 | +export default { |
| 54 | + setup() { |
| 55 | + const toast = useToast(); |
| 56 | + const store = useStore(); |
| 57 | +
|
| 58 | + const projectModal = shallowReactive({ |
| 59 | + name: '', |
| 60 | + path: '', |
| 61 | + show: false, |
| 62 | + starred: false, |
| 63 | + }); |
| 64 | + const { ipcRenderer } = window.electron; |
| 65 | +
|
| 66 | + function selectDirectory() { |
| 67 | + ipcRenderer.invoke('select-dir').then(({ canceled, path, config }) => { |
| 68 | + if (canceled) return; |
| 69 | +
|
| 70 | + projectModal.path = path; |
| 71 | + projectModal.name = config.name || path.split('\\').pop(); |
| 72 | + }).catch((error) => { |
| 73 | + toast.error('Can\'t find package.json'); |
| 74 | + }); |
| 75 | + } |
| 76 | + function importProject() { |
| 77 | + if (!projectModal.name || !projectModal.path) return; |
| 78 | +
|
| 79 | + const copy = { ...projectModal }; |
| 80 | +
|
| 81 | + delete copy.show; |
| 82 | +
|
| 83 | + store.dispatch('projects/add', copy).then(() => { |
| 84 | + projectModal.show = false; |
| 85 | + projectModal.name = projectModal.path = ''; |
| 86 | + }).catch((error) => { |
| 87 | + toast.error(error); |
| 88 | + }); |
| 89 | + } |
| 90 | +
|
| 91 | + return { |
| 92 | + projectModal, |
| 93 | + importProject, |
| 94 | + selectDirectory, |
| 95 | + }; |
| 96 | + } |
| 97 | +}; |
| 98 | +</script> |
0 commit comments