2020-08-18 08:44:21 -05:00
|
|
|
<template>
|
2022-06-20 03:38:49 -05:00
|
|
|
<MkStickyContainer>
|
|
|
|
<template #header><MkPageHeader :actions="headerActions" :tabs="headerTabs"/></template>
|
|
|
|
<MkSpacer :content-max="700">
|
2023-04-08 18:22:49 -05:00
|
|
|
<div v-if="channelId == null || channel != null" class="_gaps_m">
|
2023-01-05 06:04:56 -06:00
|
|
|
<MkInput v-model="name">
|
2022-07-20 08:24:26 -05:00
|
|
|
<template #label>{{ i18n.ts.name }}</template>
|
2022-06-20 03:38:49 -05:00
|
|
|
</MkInput>
|
|
|
|
|
2023-01-05 06:04:56 -06:00
|
|
|
<MkTextarea v-model="description">
|
2022-07-20 08:24:26 -05:00
|
|
|
<template #label>{{ i18n.ts.description }}</template>
|
2022-06-20 03:38:49 -05:00
|
|
|
</MkTextarea>
|
|
|
|
|
2023-05-01 19:36:40 -05:00
|
|
|
<MkColorInput v-model="color">
|
|
|
|
<template #label>{{ i18n.ts.color }}</template>
|
|
|
|
</MkColorInput>
|
|
|
|
|
2023-03-31 01:01:56 -05:00
|
|
|
<div>
|
2022-12-19 04:01:30 -06:00
|
|
|
<MkButton v-if="bannerId == null" @click="setBannerImage"><i class="ti ti-plus"></i> {{ i18n.ts._channel.setBanner }}</MkButton>
|
2022-06-20 03:38:49 -05:00
|
|
|
<div v-else-if="bannerUrl">
|
|
|
|
<img :src="bannerUrl" style="width: 100%;"/>
|
2022-12-19 04:01:30 -06:00
|
|
|
<MkButton @click="removeBannerImage()"><i class="ti ti-trash"></i> {{ i18n.ts._channel.removeBanner }}</MkButton>
|
2022-06-20 03:38:49 -05:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-03-31 01:01:56 -05:00
|
|
|
|
|
|
|
<MkFolder :default-open="true">
|
|
|
|
<template #label>{{ i18n.ts.pinnedNotes }}</template>
|
|
|
|
|
|
|
|
<div class="_gaps">
|
|
|
|
<MkButton primary rounded @click="addPinnedNote()"><i class="ti ti-plus"></i></MkButton>
|
|
|
|
|
|
|
|
<Sortable
|
|
|
|
v-model="pinnedNotes"
|
|
|
|
item-key="id"
|
|
|
|
:handle="'.' + $style.pinnedNoteHandle"
|
|
|
|
:animation="150"
|
|
|
|
>
|
|
|
|
<template #item="{element,index}">
|
|
|
|
<div :class="$style.pinnedNote">
|
|
|
|
<button class="_button" :class="$style.pinnedNoteHandle"><i class="ti ti-menu"></i></button>
|
|
|
|
{{ element.id }}
|
|
|
|
<button class="_button" :class="$style.pinnedNoteRemove" @click="removePinnedNote(index)"><i class="ti ti-x"></i></button>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</Sortable>
|
|
|
|
</div>
|
|
|
|
</MkFolder>
|
|
|
|
|
2023-01-05 06:04:56 -06:00
|
|
|
<div>
|
2022-12-19 04:01:30 -06:00
|
|
|
<MkButton primary @click="save()"><i class="ti ti-device-floppy"></i> {{ channelId ? i18n.ts.save : i18n.ts.create }}</MkButton>
|
2020-08-18 08:44:21 -05:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-06-20 03:38:49 -05:00
|
|
|
</MkSpacer>
|
|
|
|
</MkStickyContainer>
|
2020-08-18 08:44:21 -05:00
|
|
|
</template>
|
|
|
|
|
2022-06-20 03:38:49 -05:00
|
|
|
<script lang="ts" setup>
|
2023-03-31 01:01:56 -05:00
|
|
|
import { computed, ref, watch, defineAsyncComponent } from 'vue';
|
2023-01-07 00:09:46 -06:00
|
|
|
import MkTextarea from '@/components/MkTextarea.vue';
|
2022-09-06 04:21:49 -05:00
|
|
|
import MkButton from '@/components/MkButton.vue';
|
2023-01-07 00:09:46 -06:00
|
|
|
import MkInput from '@/components/MkInput.vue';
|
2023-05-01 19:36:40 -05:00
|
|
|
import MkColorInput from '@/components/MkColorInput.vue';
|
2021-11-11 11:02:25 -06:00
|
|
|
import { selectFile } from '@/scripts/select-file';
|
|
|
|
import * as os from '@/os';
|
2022-06-20 03:38:49 -05:00
|
|
|
import { useRouter } from '@/router';
|
|
|
|
import { definePageMetadata } from '@/scripts/page-metadata';
|
|
|
|
import { i18n } from '@/i18n';
|
2023-03-31 01:01:56 -05:00
|
|
|
import MkFolder from '@/components/MkFolder.vue';
|
|
|
|
|
|
|
|
const Sortable = defineAsyncComponent(() => import('vuedraggable').then(x => x.default));
|
2022-06-20 03:38:49 -05:00
|
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
channelId?: string;
|
|
|
|
}>();
|
|
|
|
|
|
|
|
let channel = $ref(null);
|
|
|
|
let name = $ref(null);
|
|
|
|
let description = $ref(null);
|
|
|
|
let bannerUrl = $ref<string | null>(null);
|
|
|
|
let bannerId = $ref<string | null>(null);
|
2023-05-01 19:36:40 -05:00
|
|
|
let color = $ref(null);
|
2023-03-31 01:01:56 -05:00
|
|
|
const pinnedNotes = ref([]);
|
2022-06-20 03:38:49 -05:00
|
|
|
|
|
|
|
watch(() => bannerId, async () => {
|
|
|
|
if (bannerId == null) {
|
|
|
|
bannerUrl = null;
|
|
|
|
} else {
|
|
|
|
bannerUrl = (await os.api('drive/files/show', {
|
|
|
|
fileId: bannerId,
|
|
|
|
})).url;
|
2020-08-18 08:44:21 -05:00
|
|
|
}
|
|
|
|
});
|
2022-06-20 03:38:49 -05:00
|
|
|
|
|
|
|
async function fetchChannel() {
|
|
|
|
if (props.channelId == null) return;
|
|
|
|
|
|
|
|
channel = await os.api('channels/show', {
|
|
|
|
channelId: props.channelId,
|
|
|
|
});
|
|
|
|
|
|
|
|
name = channel.name;
|
|
|
|
description = channel.description;
|
|
|
|
bannerId = channel.bannerId;
|
|
|
|
bannerUrl = channel.bannerUrl;
|
2023-03-31 01:01:56 -05:00
|
|
|
pinnedNotes.value = channel.pinnedNoteIds.map(id => ({
|
|
|
|
id,
|
|
|
|
}));
|
2023-05-01 19:36:40 -05:00
|
|
|
color = channel.color;
|
2022-06-20 03:38:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fetchChannel();
|
|
|
|
|
2023-03-31 01:01:56 -05:00
|
|
|
async function addPinnedNote() {
|
|
|
|
const { canceled, result: value } = await os.inputText({
|
|
|
|
title: i18n.ts.noteIdOrUrl,
|
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
const note = await os.apiWithDialog('notes/show', {
|
|
|
|
noteId: value.includes('/') ? value.split('/').pop() : value,
|
|
|
|
});
|
|
|
|
pinnedNotes.value = [{
|
|
|
|
id: note.id,
|
|
|
|
}, ...pinnedNotes.value];
|
|
|
|
}
|
|
|
|
|
|
|
|
function removePinnedNote(index: number) {
|
|
|
|
pinnedNotes.value.splice(index, 1);
|
|
|
|
}
|
|
|
|
|
2022-06-20 03:38:49 -05:00
|
|
|
function save() {
|
|
|
|
const params = {
|
|
|
|
name: name,
|
|
|
|
description: description,
|
|
|
|
bannerId: bannerId,
|
2023-03-31 01:01:56 -05:00
|
|
|
pinnedNoteIds: pinnedNotes.value.map(x => x.id),
|
2023-05-01 19:36:40 -05:00
|
|
|
color: color,
|
2022-06-20 03:38:49 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
if (props.channelId) {
|
|
|
|
params.channelId = props.channelId;
|
|
|
|
os.api('channels/update', params).then(() => {
|
|
|
|
os.success();
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
os.api('channels/create', params).then(created => {
|
|
|
|
os.success();
|
|
|
|
router.push(`/channels/${created.id}`);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function setBannerImage(evt) {
|
|
|
|
selectFile(evt.currentTarget ?? evt.target, null).then(file => {
|
|
|
|
bannerId = file.id;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeBannerImage() {
|
|
|
|
bannerId = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const headerActions = $computed(() => []);
|
|
|
|
|
|
|
|
const headerTabs = $computed(() => []);
|
|
|
|
|
|
|
|
definePageMetadata(computed(() => props.channelId ? {
|
|
|
|
title: i18n.ts._channel.edit,
|
2022-12-19 04:01:30 -06:00
|
|
|
icon: 'ti ti-device-tv',
|
2022-06-20 03:38:49 -05:00
|
|
|
} : {
|
|
|
|
title: i18n.ts._channel.create,
|
2022-12-19 04:01:30 -06:00
|
|
|
icon: 'ti ti-device-tv',
|
2022-06-20 03:38:49 -05:00
|
|
|
}));
|
2020-08-18 08:44:21 -05:00
|
|
|
</script>
|
|
|
|
|
2023-03-31 01:01:56 -05:00
|
|
|
<style lang="scss" module>
|
|
|
|
.pinnedNote {
|
|
|
|
position: relative;
|
|
|
|
display: block;
|
|
|
|
line-height: 2.85rem;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
overflow: hidden;
|
|
|
|
white-space: nowrap;
|
|
|
|
color: var(--navFg);
|
|
|
|
}
|
2020-08-18 08:44:21 -05:00
|
|
|
|
2023-03-31 01:01:56 -05:00
|
|
|
.pinnedNoteRemove {
|
|
|
|
position: absolute;
|
|
|
|
z-index: 10000;
|
|
|
|
width: 32px;
|
|
|
|
height: 32px;
|
|
|
|
color: #ff2a2a;
|
|
|
|
right: 8px;
|
|
|
|
opacity: 0.8;
|
|
|
|
}
|
|
|
|
|
|
|
|
.pinnedNoteHandle {
|
|
|
|
cursor: move;
|
|
|
|
width: 32px;
|
|
|
|
height: 32px;
|
|
|
|
margin: 0 8px;
|
|
|
|
opacity: 0.5;
|
|
|
|
}
|
2020-08-18 08:44:21 -05:00
|
|
|
</style>
|