2024-10-28 16:15:05 -04:00
|
|
|
<script lang="ts" setup>
|
2024-07-07 11:32:30 -04:00
|
|
|
import {SvgIcon} from '../svg.ts';
|
|
|
|
import {GET} from '../modules/fetch.ts';
|
2024-10-29 05:20:49 -04:00
|
|
|
import {getIssueColor, getIssueIcon} from '../features/issue.ts';
|
2024-10-28 16:15:05 -04:00
|
|
|
import {computed, onMounted, ref} from 'vue';
|
2021-07-13 14:09:19 -04:00
|
|
|
|
2021-12-28 08:28:27 -05:00
|
|
|
const {appSubUrl, i18n} = window.config;
|
2021-07-13 14:09:19 -04:00
|
|
|
|
2024-10-28 16:15:05 -04:00
|
|
|
const loading = ref(false);
|
|
|
|
const issue = ref(null);
|
|
|
|
const renderedLabels = ref('');
|
|
|
|
const i18nErrorOccurred = i18n.error_occurred;
|
|
|
|
const i18nErrorMessage = ref(null);
|
2021-07-13 14:09:19 -04:00
|
|
|
|
2024-10-28 16:15:05 -04:00
|
|
|
const createdAt = computed(() => new Date(issue.value.created_at).toLocaleDateString(undefined, {year: 'numeric', month: 'short', day: 'numeric'}));
|
|
|
|
const body = computed(() => {
|
|
|
|
const body = issue.value.body.replace(/\n+/g, ' ');
|
|
|
|
if (body.length > 85) {
|
|
|
|
return `${body.substring(0, 85)}…`;
|
|
|
|
}
|
|
|
|
return body;
|
|
|
|
});
|
2021-07-13 14:09:19 -04:00
|
|
|
|
2024-10-28 16:15:05 -04:00
|
|
|
const root = ref<HTMLElement | null>(null);
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
root.value.addEventListener('ce-load-context-popup', (e: CustomEvent) => {
|
|
|
|
const data = e.detail;
|
|
|
|
if (!loading.value && issue.value === null) {
|
|
|
|
load(data);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
async function load(data) {
|
|
|
|
loading.value = true;
|
|
|
|
i18nErrorMessage.value = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
const response = await GET(`${appSubUrl}/${data.owner}/${data.repo}/issues/${data.index}/info`); // backend: GetIssueInfo
|
|
|
|
const respJson = await response.json();
|
|
|
|
if (!response.ok) {
|
|
|
|
i18nErrorMessage.value = respJson.message ?? i18n.network_error;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
issue.value = respJson.convertedIssue;
|
|
|
|
renderedLabels.value = respJson.renderedLabels;
|
|
|
|
} catch {
|
|
|
|
i18nErrorMessage.value = i18n.network_error;
|
|
|
|
} finally {
|
|
|
|
loading.value = false;
|
|
|
|
}
|
|
|
|
}
|
2021-07-13 14:09:19 -04:00
|
|
|
</script>
|
2024-10-28 16:15:05 -04:00
|
|
|
|
2023-09-02 10:59:07 -04:00
|
|
|
<template>
|
|
|
|
<div ref="root">
|
2024-03-27 16:18:04 -04:00
|
|
|
<div v-if="loading" class="tw-h-12 tw-w-12 is-loading"/>
|
2024-05-02 09:42:33 -04:00
|
|
|
<div v-if="!loading && issue !== null" class="tw-flex tw-flex-col tw-gap-2">
|
|
|
|
<div class="tw-text-12">{{ issue.repository.full_name }} on {{ createdAt }}</div>
|
|
|
|
<div class="flex-text-block">
|
2024-10-28 16:15:05 -04:00
|
|
|
<svg-icon :name="getIssueIcon(issue)" :class="['text', getIssueColor(issue)]"/>
|
2024-05-02 09:42:33 -04:00
|
|
|
<span class="issue-title tw-font-semibold tw-break-anywhere">
|
|
|
|
{{ issue.title }}
|
|
|
|
<span class="index">#{{ issue.number }}</span>
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
<div v-if="body">{{ body }}</div>
|
2024-04-29 22:36:32 -04:00
|
|
|
<!-- eslint-disable-next-line vue/no-v-html -->
|
2024-05-02 09:42:33 -04:00
|
|
|
<div v-if="issue.labels.length" v-html="renderedLabels"/>
|
2023-09-02 10:59:07 -04:00
|
|
|
</div>
|
2024-05-02 09:42:33 -04:00
|
|
|
<div class="tw-flex tw-flex-col tw-gap-2" v-if="!loading && issue === null">
|
|
|
|
<div class="tw-text-12">{{ i18nErrorOccurred }}</div>
|
|
|
|
<div>{{ i18nErrorMessage }}</div>
|
2023-09-02 10:59:07 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|