mirror of
https://codeberg.org/yeentown/barkey
synced 2024-11-22 19:35:12 +00:00
Refactor clip page to Composition API (#8822)
* Refactor clip page to use Composition API * Refactor clip page * Refactor clip page * Refactor clip page
This commit is contained in:
parent
6422cde5f2
commit
d7bab7cf0b
1 changed files with 73 additions and 104 deletions
|
@ -15,121 +15,90 @@
|
||||||
</MkSpacer>
|
</MkSpacer>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts" setup>
|
||||||
import { computed, defineComponent } from 'vue';
|
import { computed, watch } from 'vue';
|
||||||
import MkContainer from '@/components/ui/container.vue';
|
import * as misskey from 'misskey-js';
|
||||||
import XPostForm from '@/components/post-form.vue';
|
|
||||||
import XNotes from '@/components/notes.vue';
|
import XNotes from '@/components/notes.vue';
|
||||||
|
import { $i } from '@/account';
|
||||||
|
import { i18n } from '@/i18n';
|
||||||
import * as os from '@/os';
|
import * as os from '@/os';
|
||||||
import * as symbols from '@/symbols';
|
import * as symbols from '@/symbols';
|
||||||
|
|
||||||
export default defineComponent({
|
const props = defineProps<{
|
||||||
components: {
|
clipId: string,
|
||||||
MkContainer,
|
}>();
|
||||||
XPostForm,
|
|
||||||
XNotes,
|
|
||||||
},
|
|
||||||
|
|
||||||
props: {
|
let clip: misskey.entities.Clip = $ref<misskey.entities.Clip>();
|
||||||
clipId: {
|
const pagination = {
|
||||||
type: String,
|
|
||||||
required: true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
[symbols.PAGE_INFO]: computed(() => this.clip ? {
|
|
||||||
title: this.clip.name,
|
|
||||||
icon: 'fas fa-paperclip',
|
|
||||||
bg: 'var(--bg)',
|
|
||||||
actions: [{
|
|
||||||
icon: 'fas fa-ellipsis-h',
|
|
||||||
handler: this.menu
|
|
||||||
}],
|
|
||||||
} : null),
|
|
||||||
clip: null,
|
|
||||||
pagination: {
|
|
||||||
endpoint: 'clips/notes' as const,
|
endpoint: 'clips/notes' as const,
|
||||||
limit: 10,
|
limit: 10,
|
||||||
params: computed(() => ({
|
params: computed(() => ({
|
||||||
clipId: this.clipId,
|
clipId: props.clipId,
|
||||||
}))
|
})),
|
||||||
},
|
|
||||||
};
|
};
|
||||||
},
|
|
||||||
|
|
||||||
computed: {
|
const isOwned: boolean | null = $computed<boolean | null>(() => $i && clip && ($i.id === clip.userId));
|
||||||
isOwned(): boolean {
|
|
||||||
return this.$i && this.clip && (this.$i.id === this.clip.userId);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
watch: {
|
watch(() => props.clipId, async () => {
|
||||||
clipId: {
|
clip = await os.api('clips/show', {
|
||||||
async handler() {
|
clipId: props.clipId,
|
||||||
this.clip = await os.api('clips/show', {
|
});
|
||||||
clipId: this.clipId,
|
}, {
|
||||||
|
immediate: true,
|
||||||
});
|
});
|
||||||
},
|
|
||||||
immediate: true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
created() {
|
defineExpose({
|
||||||
|
[symbols.PAGE_INFO]: computed(() => clip ? {
|
||||||
},
|
title: clip.name,
|
||||||
|
icon: 'fas fa-paperclip',
|
||||||
methods: {
|
bg: 'var(--bg)',
|
||||||
menu(ev) {
|
actions: isOwned ? [{
|
||||||
os.popupMenu([this.isOwned ? {
|
|
||||||
icon: 'fas fa-pencil-alt',
|
icon: 'fas fa-pencil-alt',
|
||||||
text: this.$ts.edit,
|
text: i18n.ts.edit,
|
||||||
action: async () => {
|
handler: async (): Promise<void> => {
|
||||||
const { canceled, result } = await os.form(this.clip.name, {
|
const { canceled, result } = await os.form(clip.name, {
|
||||||
name: {
|
name: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
label: this.$ts.name,
|
label: i18n.ts.name,
|
||||||
default: this.clip.name
|
default: clip.name,
|
||||||
},
|
},
|
||||||
description: {
|
description: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
required: false,
|
required: false,
|
||||||
multiline: true,
|
multiline: true,
|
||||||
label: this.$ts.description,
|
label: i18n.ts.description,
|
||||||
default: this.clip.description
|
default: clip.description,
|
||||||
},
|
},
|
||||||
isPublic: {
|
isPublic: {
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
label: this.$ts.public,
|
label: i18n.ts.public,
|
||||||
default: this.clip.isPublic
|
default: clip.isPublic,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
if (canceled) return;
|
if (canceled) return;
|
||||||
|
|
||||||
os.apiWithDialog('clips/update', {
|
os.apiWithDialog('clips/update', {
|
||||||
clipId: this.clip.id,
|
clipId: clip.id,
|
||||||
...result
|
...result,
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
} : undefined, this.isOwned ? {
|
}, {
|
||||||
icon: 'fas fa-trash-alt',
|
icon: 'fas fa-trash-alt',
|
||||||
text: this.$ts.delete,
|
text: i18n.ts.delete,
|
||||||
danger: true,
|
danger: true,
|
||||||
action: async () => {
|
handler: async (): Promise<void> => {
|
||||||
const { canceled } = await os.confirm({
|
const { canceled } = await os.confirm({
|
||||||
type: 'warning',
|
type: 'warning',
|
||||||
text: this.$t('deleteAreYouSure', { x: this.clip.name }),
|
text: i18n.t('deleteAreYouSure', { x: clip.name }),
|
||||||
});
|
});
|
||||||
if (canceled) return;
|
if (canceled) return;
|
||||||
|
|
||||||
await os.apiWithDialog('clips/delete', {
|
await os.apiWithDialog('clips/delete', {
|
||||||
clipId: this.clip.id,
|
clipId: clip.id,
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
} : undefined], ev.currentTarget ?? ev.target);
|
}] : [],
|
||||||
}
|
} : null),
|
||||||
}
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue