refactor: ♻️ MkPostFormAttachees setup syntax

This commit is contained in:
ThatOneCalculator 2023-07-11 19:38:49 -07:00
parent d6dd1bc43c
commit e57a9a075c
No known key found for this signature in database
GPG key ID: 8703CACD01000000

View file

@ -29,20 +29,14 @@
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts" setup>
import { defineComponent, defineAsyncComponent } from "vue"; import { defineAsyncComponent, ref, computed } from "vue";
import { VueDraggable } from "vue-draggable-plus"; import { VueDraggable } from "vue-draggable-plus";
import MkDriveFileThumbnail from "@/components/MkDriveFileThumbnail.vue"; import MkDriveFileThumbnail from "@/components/MkDriveFileThumbnail.vue";
import * as os from "@/os"; import * as os from "@/os";
import { i18n } from "@/i18n"; import { i18n } from "@/i18n";
export default defineComponent({ const props = defineProps({
components: {
VueDraggable,
MkDriveFileThumbnail,
},
props: {
files: { files: {
type: Array, type: Array,
required: true, required: true,
@ -51,65 +45,57 @@ export default defineComponent({
type: Function, type: Function,
required: false, required: false,
}, },
}, });
emits: ["updated", "detach", "changeSensitive", "changeName"], const emits = defineEmits([
"updated",
"detach",
"changeSensitive",
"changeName",
]);
data() { let menu = ref<Promise<any> | null>(null);
return {
menu: null as Promise<null> | null,
i18n,
};
},
computed: { const _files = computed({
_files: { get: () => props.files,
get() { set: (value) => emits("updated", value),
return this.files; });
},
set(value) {
this.$emit("updated", value);
},
},
},
methods: { const detachMedia = (id) => {
detachMedia(id) { if (props.detachMediaFn) {
if (this.detachMediaFn) { props.detachMediaFn(id);
this.detachMediaFn(id);
} else { } else {
this.$emit("detach", id); emits("detach", id);
} }
}, };
toggleSensitive(file) {
function toggleSensitive(file) {
os.api("drive/files/update", { os.api("drive/files/update", {
fileId: file.id, fileId: file.id,
isSensitive: !file.isSensitive, isSensitive: !file.isSensitive,
}).then(() => { }).then(() => {
this.$emit("changeSensitive", file, !file.isSensitive); emits("changeSensitive", file, !file.isSensitive);
}); });
}, }
async rename(file) {
async function rename(file) {
const { canceled, result } = await os.inputText({ const { canceled, result } = await os.inputText({
title: i18n.ts.enterFileName, title: i18n.ts.enterFileName,
default: file.name, default: file.name,
allowEmpty: false,
}); });
if (canceled) return; if (canceled) return;
os.api("drive/files/update", { os.api("drive/files/update", {
fileId: file.id, fileId: file.id,
name: result, name: result,
}).then(() => { }).then(() => {
this.$emit("changeName", file, result); emits("changeName", file, result);
file.name = result; file.name = result;
}); });
}, }
async describe(file) { async function describe(file) {
os.popup( os.popup(
defineAsyncComponent( defineAsyncComponent(() => import("@/components/MkMediaCaption.vue")),
() => import("@/components/MkMediaCaption.vue"),
),
{ {
title: i18n.ts.describeFile, title: i18n.ts.describeFile,
input: { input: {
@ -121,8 +107,7 @@ export default defineComponent({
{ {
done: (result) => { done: (result) => {
if (!result || result.canceled) return; if (!result || result.canceled) return;
let comment = let comment = result.result.length === 0 ? null : result.result;
result.result.length === 0 ? null : result.result;
os.api("drive/files/update", { os.api("drive/files/update", {
fileId: file.id, fileId: file.id,
comment: comment, comment: comment,
@ -133,18 +118,18 @@ export default defineComponent({
}, },
"closed", "closed",
); );
}, }
showFileMenu(file, ev: MouseEvent) { function showFileMenu(file, ev: MouseEvent) {
if (this.menu) return; if (menu) return;
this.menu = os menu = os
.popupMenu( .popupMenu(
[ [
{ {
text: i18n.ts.renameFile, text: i18n.ts.renameFile,
icon: "ph-cursor-text ph-bold ph-lg", icon: "ph-cursor-text ph-bold ph-lg",
action: () => { action: () => {
this.rename(file); rename(file);
}, },
}, },
{ {
@ -155,30 +140,28 @@ export default defineComponent({
? "ph-eye ph-bold ph-lg" ? "ph-eye ph-bold ph-lg"
: "ph-eye-slash ph-bold ph-lg", : "ph-eye-slash ph-bold ph-lg",
action: () => { action: () => {
this.toggleSensitive(file); toggleSensitive(file);
}, },
}, },
{ {
text: i18n.ts.describeFile, text: i18n.ts.describeFile,
icon: "ph-subtitles ph-bold ph-lg", icon: "ph-subtitles ph-bold ph-lg",
action: () => { action: () => {
this.describe(file); describe(file);
}, },
}, },
{ {
text: i18n.ts.attachCancel, text: i18n.ts.attachCancel,
icon: "ph-x ph-bold ph-lg", icon: "ph-x ph-bold ph-lg",
action: () => { action: () => {
this.detachMedia(file.id); detachMedia(file.id);
}, },
}, },
], ],
ev.currentTarget ?? ev.target, ev.currentTarget ?? ev.target,
) )
.then(() => (this.menu = null)); .then(() => (menu = null));
}, }
},
});
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@ -217,8 +200,8 @@ export default defineComponent({
top: 0; top: 0;
left: 0; left: 0;
z-index: 2; z-index: 2;
background: rgba(17, 17, 17, 0.7); background: var(--header);
color: #fff; color: var(--fg);
> .icon { > .icon {
margin: auto; margin: auto;