refactor: NodeShareModal

pull/474/head
Varun Patil 2023-03-10 12:34:03 -08:00
parent af6c142db2
commit 5a846cbde6
2 changed files with 25 additions and 15 deletions

View File

@ -3,7 +3,7 @@
@close="close" @close="close"
size="normal" size="normal"
v-if="show" v-if="show"
:sidebar="!isRoot ? this.folderPath : null" :sidebar="!isRoot ? this.filename : null"
> >
<template #title> <template #title>
{{ t("memories", "Link Sharing") }} {{ t("memories", "Link Sharing") }}
@ -91,6 +91,7 @@ import { API } from "../../services/API";
import CloseIcon from "vue-material-design-icons/Close.vue"; import CloseIcon from "vue-material-design-icons/Close.vue";
import LinkIcon from "vue-material-design-icons/LinkVariant.vue"; import LinkIcon from "vue-material-design-icons/LinkVariant.vue";
import { IPhoto } from "../../types";
type IShare = { type IShare = {
id: string; id: string;
@ -103,7 +104,7 @@ type IShare = {
}; };
export default defineComponent({ export default defineComponent({
name: "FolderShareModal", name: "NodeShareModal",
components: { components: {
Modal, Modal,
NcButton, NcButton,
@ -119,14 +120,14 @@ export default defineComponent({
data: () => ({ data: () => ({
show: false, show: false,
folderPath: "", filename: "",
loading: false, loading: false,
shares: [] as IShare[], shares: [] as IShare[],
}), }),
computed: { computed: {
isRoot(): boolean { isRoot(): boolean {
return this.folderPath === "/" || this.folderPath === ""; return this.filename === "/" || this.filename === "";
}, },
}, },
@ -139,23 +140,32 @@ export default defineComponent({
}, },
methods: { methods: {
close() { openFolder() {
this.show = false; this.filename = utils.getFolderRoutePath(this.config_foldersPath);
this.$emit("close"); this.open();
},
openPhoto(photo: IPhoto) {
this.filename = photo.filename;
this.open();
}, },
open() { open() {
this.folderPath = utils.getFolderRoutePath(this.config_foldersPath);
this.show = true; this.show = true;
globalThis.mSidebar.setTab("sharing"); globalThis.mSidebar.setTab("sharing");
this.refreshUrls(); this.refreshUrls();
}, },
close() {
this.show = false;
this.$emit("close");
},
async refreshUrls() { async refreshUrls() {
this.loading = true; this.loading = true;
try { try {
this.shares = ( this.shares = (
await axios.get(API.Q(API.SHARE_LINKS(), { path: this.folderPath })) await axios.get(API.Q(API.SHARE_LINKS(), { path: this.filename }))
).data; ).data;
} finally { } finally {
this.loading = false; this.loading = false;
@ -188,7 +198,7 @@ export default defineComponent({
async createLink() { async createLink() {
this.loading = true; this.loading = true;
try { try {
await axios.post(API.SHARE_NODE(), { path: this.folderPath }); await axios.post(API.SHARE_NODE(), { path: this.filename });
} finally { } finally {
this.loading = false; this.loading = false;
} }
@ -215,7 +225,7 @@ export default defineComponent({
refreshSidebar() { refreshSidebar() {
globalThis.mSidebar.close(); globalThis.mSidebar.close();
globalThis.mSidebar.open({ globalThis.mSidebar.open({
filename: this.folderPath, filename: this.filename,
} as any); } as any);
}, },
}, },

View File

@ -32,7 +32,7 @@
</NcActionRouter> </NcActionRouter>
<NcActionButton <NcActionButton
:aria-label="t('memories', 'Share folder')" :aria-label="t('memories', 'Share folder')"
@click="$refs.shareModal.open(false)" @click="$refs.shareModal.openFolder()"
close-after-click close-after-click
> >
{{ t("memories", "Share folder") }} {{ t("memories", "Share folder") }}
@ -41,7 +41,7 @@
</NcActions> </NcActions>
</div> </div>
<FolderShareModal ref="shareModal" /> <NodeShareModal ref="shareModal" />
</div> </div>
</template> </template>
@ -57,7 +57,7 @@ import NcActions from "@nextcloud/vue/dist/Components/NcActions";
import NcActionButton from "@nextcloud/vue/dist/Components/NcActionButton"; import NcActionButton from "@nextcloud/vue/dist/Components/NcActionButton";
import NcActionRouter from "@nextcloud/vue/dist/Components/NcActionRouter"; import NcActionRouter from "@nextcloud/vue/dist/Components/NcActionRouter";
import FolderShareModal from "../modal/FolderShareModal.vue"; import NodeShareModal from "../modal/NodeShareModal.vue";
import HomeIcon from "vue-material-design-icons/Home.vue"; import HomeIcon from "vue-material-design-icons/Home.vue";
import ShareIcon from "vue-material-design-icons/ShareVariant.vue"; import ShareIcon from "vue-material-design-icons/ShareVariant.vue";
@ -72,7 +72,7 @@ export default defineComponent({
NcActions, NcActions,
NcActionButton, NcActionButton,
NcActionRouter, NcActionRouter,
FolderShareModal, NodeShareModal,
HomeIcon, HomeIcon,
ShareIcon, ShareIcon,
TimelineIcon, TimelineIcon,