Skip to content

Commit

Permalink
#10 - Updated design & Added shortcut edit functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Anders164a committed Oct 16, 2023
1 parent 2a4a7e4 commit fdcaa3e
Show file tree
Hide file tree
Showing 9 changed files with 266 additions and 62 deletions.
34 changes: 13 additions & 21 deletions src/components/item/CreateShortcutModal.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<BaseModal ref="modal" @close="close">
<h3 class="mb-4 text-xl font-medium">{{ t('item.createShortcut') }}</h3>
<h3 class="mb-4 text-xl font-medium">{{ t('fileBrowser.shortcut.create') }}</h3>
<hr>
<div class="mb-5">
<div class="relative inline-flex items-center w-full hover:bg-gray-600 py-1"
Expand Down Expand Up @@ -57,9 +57,10 @@ defineExpose({
const modal = ref<InstanceType<typeof BaseModal>>();
const item = ref<{ id: number; name: string; }>({
const item = ref<{ id: number; name: string; parentId: number | null; }>({
id: props.item.id,
name: props.item.name,
parentId: props.item.parentId,
});
let selectedFolder: number;
Expand Down Expand Up @@ -97,21 +98,8 @@ async function selectFolder(parentId: number) {
}
async function childFolder(parentId: number) {
alert(parentId);
//errorObject.value = null;
//try {
/*const updatedFolder = await props.folder.update({
name: folder.value.name,
color: folder.value.color,
});
updateItem(updatedFolder);*/
// TODO: Show success toast
// close();
//} catch (e) { }
folders.value = [];
getFolders(parentId);
}
async function createShortcut() {
Expand All @@ -135,18 +123,22 @@ function close() {
item.value = {
id: props.item.id,
name: props.item.name,
parentId: props.item.parentId,
};
folders.value = [];
getFolders(null);
modal.value?.close(false);
}
const fileBrowserFolder = ref<FolderClass | null>(null);
const hasItemsLoaded = ref(false);
const folders = ref<FolderClass[]>([]);
async function getFolders() {
async function getFolders(folderId: number | null) {
try {
const response = await fetch(
api(`item/${FolderClass.isFolder(fileBrowserFolder) ? `${fileBrowserFolder.id}` : ''}`),
api(`item/${folderId ? `${folderId}` : ''}`),
{
method: 'GET',
headers: {
Expand Down Expand Up @@ -184,5 +176,5 @@ async function getFolders() {
hasItemsLoaded.value = true;
}
getFolders();
getFolders(item.value.parentId);
</script>
84 changes: 84 additions & 0 deletions src/components/item/file/EditShortcutModal.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<template>
<BaseModal ref="modal" @close="close">
<h3 class="mb-4 text-xl font-medium">{{ t('fileBrowser.shortcut.rename') }}</h3>
<form class="space-y-6" @submit.prevent="updateFile" ref="form">
<BaseInput
id="fileName"
type="text"
v-model="shortcut.name"
:required="true"
:errors="errorObject?.errors.name"
>{{ t('fileBrowser.file.name') }}</BaseInput
>
<BaseButton type="submit" :color="ButtonColor.Primary">{{
t('fileBrowser.folder.edit')
}}</BaseButton>
<ErrorAlert v-if="errorObject" :errorObject="errorObject"></ErrorAlert>
</form>
</BaseModal>
</template>

<script setup lang="ts">
import { updateItem } from '@stores/items';
import { ref, type PropType } from 'vue';
import BaseModal from '@components/base/modal.vue';
import BaseInput from '@components/base/input.vue';
import BaseButton, { ButtonColor } from '@components/base/button.vue';
import ErrorAlert, { type ErrorObject } from '@components/base/errorAlert.vue';
import { t } from '@lib/i18n';
import type { ShortcutClass } from '@lib/items/shortcuts';
const props = defineProps({
shortcut: {
type: Object as PropType<ShortcutClass>,
required: true,
},
});
defineExpose({
open,
close,
});
const modal = ref<InstanceType<typeof BaseModal>>();
const shortcut = ref<{ name: string }>({
name: props.shortcut.name,
});
const form = ref<HTMLFormElement>();
const errorObject = ref<null | ErrorObject>(null);
async function updateFile() {
errorObject.value = null;
if (!form.value?.checkValidity() || errorObject.value) {
form.value?.reportValidity();
return;
}
try {
const updatedShortcut = await props.shortcut.update({
name: shortcut.value.name,
});
await updatedShortcut.setLinkedItem(updatedShortcut._linkedItemId);
updateItem(updatedShortcut);
// TODO: Show success toast
close();
} catch (e) {}
}
function open() {
modal.value?.open();
}
function close() {
shortcut.value = {
name: props.shortcut.name,
};
modal.value?.close(false);
}
</script>
36 changes: 20 additions & 16 deletions src/components/item/file/File.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,39 @@
class="block max-w-sm rounded-lg border border-gray-200 bg-white p-6 shadow hover:bg-gray-100 dark:border-gray-700 dark:bg-gray-800 dark:hover:bg-gray-700"
v-on:contextmenu.prevent="fileContextMenu?.openMenu"
>
<h5 class="mb-2 text-2xl font-bold tracking-tight text-gray-900 dark:text-white">
<h5 class="mb-2 text-2xl font-bold tracking-tight text-gray-900 dark:text-white flex items-center gap-2">
{{ modelValue.name }}
<svg v-if="(modelValue instanceof ShortcutClass)" class="w-6 h-6 text-gray-800 dark:text-white" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 19 17">
<path d="M2.057 6.9a8.718 8.718 0 0 1 6.41-3.62v-1.2A2.064 2.064 0 0 1 9.626.2a1.979 1.979 0 0 1 2.1.23l5.481 4.308a2.107 2.107 0 0 1 0 3.3l-5.479 4.308a1.977 1.977 0 0 1-2.1.228 2.063 2.063 0 0 1-1.158-1.876v-.942c-5.32 1.284-6.2 5.25-6.238 5.44a1 1 0 0 1-.921.807h-.06a1 1 0 0 1-.953-.7A10.24 10.24 0 0 1 2.057 6.9Z"/>
</svg>
</h5>
<svg v-if="(modelValue instanceof ShortcutClass)" class="absolute -left-6 -bottom-1/3" fill="lightblue" version="1.0" xmlns="http://www.w3.org/2000/svg"
width="50.000000pt" height="50.000000pt" viewBox="0 0 50.000000 50.000000"
preserveAspectRatio="xMidYMid meet">
<g transform="translate(0.000000,50.000000) scale(0.100000,-0.100000)" stroke="black" stroke-width="6px">
<path d="M236 449 c-49 -10 -92 -21 -95 -24 -3 -3 8 -16 24 -29 l30 -24 -25
-43 c-19 -35 -25 -58 -25 -109 1 -68 19 -114 69 -175 30 -37 43 -28 22 14 -30
57 -14 146 39 215 15 19 15 19 38 -2 42 -40 47 -30 47 88 0 127 12 118 -124
89z"/>
</g>
</svg>
</a>

<!-- File ContextMenu -->
<ContextMenu ref="fileContextMenu">
<ul class="py-2 text-sm text-gray-700 dark:text-gray-200">
<li>
<li v-if="(modelValue instanceof ShortcutClass)">
<a
href="javascript:void(0)"
@click="editShortcutModal?.open()"
class="block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white"
>{{ t('fileBrowser.shortcut.rename') }}</a
>
</li>
<li v-else>
<a
href="javascript:void(0)"
@click="editFileModal?.open()"
class="block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white"
>{{ t('fileBrowser.file.rename') }}</a
>
</li>
<li>
<li v-if="!(modelValue instanceof ShortcutClass)">
<a
href="javascript:void(0)"
@click="createShortcutModal?.open()"
class="block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white"
>{{ t('item.createShortcut') }}</a
>{{ t('fileBrowser.shortcut.create') }}</a
>
</li>
<li>
Expand All @@ -64,7 +65,8 @@
<BaseConfirmModal ref="deleteFileModal" :type="ConfirmModalType.Danger" @confirm="deleteFile">
{{ t('fileBrowser.file.areYouSureYouWantToDeleteThisFile') }}</BaseConfirmModal
>
<EditFileModal ref="editFileModal" :file="modelValue" />
<EditFileModal v-if="(modelValue instanceof FileClass)" ref="editFileModal" :file="modelValue" />
<EditShortcutModal v-if="(modelValue instanceof ShortcutClass)" ref="editShortcutModal" :shortcut="modelValue" />
<ShareItemModal ref="shareItemModal" :item="modelValue" />
<CreateShortcutModal ref="createShortcutModal" :item="modelValue" />
</template>
Expand All @@ -76,6 +78,7 @@ import { ShortcutClass } from '@lib/items/shortcuts';
import ContextMenu from '@components/base/contextMenu.vue';
import BaseConfirmModal, { ConfirmModalType } from '@components/base/confirmModal.vue';
import EditFileModal from './EditModal.vue';
import EditShortcutModal from './EditShortcutModal.vue';
import ShareItemModal from '../ShareItemModal.vue';
import CreateShortcutModal from '../CreateShortcutModal.vue';
import { t } from '@lib/i18n';
Expand All @@ -86,7 +89,7 @@ const fileContextMenu = ref<InstanceType<typeof ContextMenu>>();
defineEmits(['update:modelValue']);
const props = defineProps({
modelValue: {
type: Object as PropType<FileClass>,
type: Object as PropType<FileClass | ShortcutClass>,
required: true,
},
});
Expand All @@ -107,6 +110,7 @@ async function deleteFile() {
}
const editFileModal = ref<InstanceType<typeof EditFileModal>>();
const editShortcutModal = ref<InstanceType<typeof EditShortcutModal>>();
const shareItemModal = ref<InstanceType<typeof ShareItemModal>>();
const createShortcutModal = ref<InstanceType<typeof CreateShortcutModal>>();
Expand Down
84 changes: 84 additions & 0 deletions src/components/item/folder/EditShortcutModal.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<template>
<BaseModal ref="modal" @close="close">
<h3 class="mb-4 text-xl font-medium">{{ t('fileBrowser.shortcut.rename') }}</h3>
<form class="space-y-6" @submit.prevent="updateFolder" ref="form">
<BaseInput
id="folderName"
type="text"
v-model="shortcut.name"
:required="true"
:errors="errorObject?.errors.name"
>{{ t('fileBrowser.folder.name') }}</BaseInput
>
<BaseButton type="submit" :color="ButtonColor.Primary">{{
t('fileBrowser.folder.edit')
}}</BaseButton>
<ErrorAlert v-if="errorObject" :errorObject="errorObject"></ErrorAlert>
</form>
</BaseModal>
</template>

<script setup lang="ts">
import { updateItem } from '@stores/items';
import { ref, type PropType } from 'vue';
import BaseModal from '@components/base/modal.vue';
import BaseInput from '@components/base/input.vue';
import BaseButton, { ButtonColor } from '@components/base/button.vue';
import ErrorAlert, { type ErrorObject } from '@components/base/errorAlert.vue';
import { t } from '@lib/i18n';
import type { ShortcutClass } from '@lib/items/shortcuts';
const props = defineProps({
shortcut: {
type: Object as PropType<ShortcutClass>,
required: true,
},
});
defineExpose({
open,
close,
});
const modal = ref<InstanceType<typeof BaseModal>>();
const shortcut = ref<{ name: string }>({
name: props.shortcut.name,
});
const form = ref<HTMLFormElement>();
const errorObject = ref<null | ErrorObject>(null);
async function updateFolder() {
errorObject.value = null;
if (!form.value?.checkValidity() || errorObject.value) {
form.value?.reportValidity();
return;
}
try {
const updatedShortcut = await props.shortcut.update({
name: shortcut.value.name,
});
await updatedShortcut.setLinkedItem(updatedShortcut._linkedItemId);
updateItem(updatedShortcut);
// TODO: Show success toast
close();
} catch (e) {}
}
function open() {
modal.value?.open();
}
function close() {
shortcut.value = {
name: props.shortcut.name,
};
modal.value?.close(false);
}
</script>
Loading

0 comments on commit fdcaa3e

Please sign in to comment.