Skip to content

Commit

Permalink
#10 - Merge from Master
Browse files Browse the repository at this point in the history
  • Loading branch information
Anders164a committed Oct 17, 2023
2 parents 40bd4d7 + 087d829 commit 5c5aaf0
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 15 deletions.
27 changes: 24 additions & 3 deletions src/components/item/SharingBrowser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<div class="mt-3 flex flex-wrap gap-3">
<!-- prettier-ignore-attribute -->
<File v-for="file in files" :key="file.id" v-model="(items[file.id] as FileClass)" />
<!-- prettier-ignore-attribute -->
<Docs v-for="doc in docs" :key="doc.id" v-model="(items[doc.id] as DocsClass)" />
</div>
</div>
</template>
Expand All @@ -27,6 +29,9 @@ import { ItemClass } from '@lib/items/items';
import { ItemFactory } from '@lib/items/factory';
import { FolderClass } from '@lib/items/folders';
import { FileClass } from '@lib/items/files';
import { ShortcutClass } from '@lib/items/shortcuts';
import { DocsClass } from '@lib/items/docs';
import Docs from './docs/Docs.vue';
/**
* Items
Expand Down Expand Up @@ -58,7 +63,7 @@ async function getItems() {
for (const rawItem of rawItems) {
if (!ItemClass.isItem(rawItem)) continue;
const item = ItemFactory.getItemFromObject(rawItem);
const item = await ItemFactory.getItemFromObject(rawItem);
if (item === null) continue;
Expand All @@ -73,13 +78,29 @@ async function getItems() {
* Folders
*/
const folders = computed(() => {
return Object.values(items.value).filter((item) => item instanceof FolderClass) as FolderClass[];
return Object.values(items.value).filter(
(item) =>
item instanceof FolderClass ||
(item instanceof ShortcutClass && item._linkedItem instanceof FolderClass),
) as FolderClass[];
});
/**
* Files
*/
const files = computed(() => {
return Object.values(items.value).filter((item) => item instanceof FileClass) as FileClass[];
return Object.values(items.value).filter(
(item) =>
item instanceof FileClass ||
(item instanceof ShortcutClass && item._linkedItem instanceof FileClass),
) as FileClass[];
});
const docs = computed(() => {
return Object.values(items.value).filter(
(item) =>
item instanceof DocsClass ||
(item instanceof ShortcutClass && item._linkedItem instanceof DocsClass),
) as DocsClass[];
});
</script>
2 changes: 1 addition & 1 deletion src/components/item/docs/Docs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
>{{ t('fileBrowser.shortcut.action.create') }}</a
>
</li>
<li>
<li v-if="!(modelValue instanceof ShortcutClass)">
<a
href="javascript:void(0)"
@click="shareItemModal?.open()"
Expand Down
57 changes: 47 additions & 10 deletions src/components/item/file/File.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
<div class="relative">
<!-- File -->
<a
href="#"
href="javascript:void(0)"
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"
@click.prevent="downloadFile"
>
<h5
class="mb-2 flex items-center gap-2 text-2xl font-bold tracking-tight text-gray-900 dark:text-white"
Expand Down Expand Up @@ -52,14 +53,22 @@
>{{ t('fileBrowser.shortcut.action.create') }}</a
>
</li>
<li>
<li v-if="!(modelValue instanceof ShortcutClass)">
<a
href="javascript:void(0)"
@click="shareItemModal?.open()"
class="block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white"
>{{ t('fileBrowser.file.action.share') }}</a
>
</li>
<li>
<a
href="javascript:void(0)"
@click="downloadFile"
class="block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white"
>{{ t('fileBrowser.file.action.download') }}</a
>
</li>
</ul>
<div class="py-2">
<a
Expand Down Expand Up @@ -87,18 +96,24 @@
</template>

<script setup lang="ts">
// Lib
import { ref, type PropType } from 'vue';
import { FileClass } from '@lib/items/files';
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';
// Helpers
import { t } from '@lib/i18n';
// Components
import ContextMenu from '@components/base/contextMenu.vue';
// Stores
import { removeItem } from '@stores/items';
// File
import { FileClass } from '@lib/items/files';
// Shortcut
import { ShortcutClass } from '@lib/items/shortcuts';
const fileContextMenu = ref<InstanceType<typeof ContextMenu>>();
defineEmits(['update:modelValue']);
Expand All @@ -109,6 +124,28 @@ const props = defineProps({
},
});
function downloadFile() {
if (
props.modelValue instanceof ShortcutClass &&
props.modelValue.linkedItem instanceof FileClass
) {
window.open(props.modelValue.linkedItem.blobUrl, '_blank');
} else if (props.modelValue instanceof FileClass) {
window.open(props.modelValue.blobUrl, '_blank');
}
fileContextMenu.value?.closeMenu();
}
/*
* Modals
*/
import BaseConfirmModal, { ConfirmModalType } from '@components/base/confirmModal.vue';
import EditFileModal from './EditModal.vue';
import ShareItemModal from '../ShareItemModal.vue';
import EditShortcutModal from './EditShortcutModal.vue';
import CreateShortcutModal from '../CreateShortcutModal.vue';
const deleteFileModal = ref<InstanceType<typeof BaseConfirmModal>>();
async function deleteFile() {
try {
Expand Down
2 changes: 1 addition & 1 deletion src/components/item/folder/Folder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
>{{ t('fileBrowser.shortcut.action.create') }}</a
>
</li>
<li>
<li v-if="!(modelValue instanceof ShortcutClass)">
<a
href="javascript:void(0)"
@click="shareItemModal?.open()"
Expand Down
1 change: 1 addition & 0 deletions src/lang/da.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export default {
edit: 'Omdøb fil',
share: 'Del',
delete: 'Slet',
download: 'Download',
confirmDelete: 'Er du sikker på, at du vil slette denne fil?',
},
},
Expand Down
1 change: 1 addition & 0 deletions src/lang/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export default {
edit: 'Rename file',
share: 'Share',
delete: 'Delete',
download: 'Download',
confirmDelete: 'Are you sure you want to delete this file?',
},
},
Expand Down

0 comments on commit 5c5aaf0

Please sign in to comment.