Fix activity comment file attach text and download.
Link uploaded attachment ids to the comment entry, label photo-only notes as file attached, and expose view/download actions for non-image files. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -16,7 +16,11 @@ import type { ActivityDto, ActivityType, OrganizationDto, OrgUserDto } from '@me
|
||||
const props = defineProps<{
|
||||
activity: ActivityDto;
|
||||
saving?: boolean;
|
||||
save: (payload: { text: string; photoOnly: boolean }) => Promise<void>;
|
||||
save: (payload: {
|
||||
text: string;
|
||||
photoOnly: boolean;
|
||||
attachmentIds?: string[];
|
||||
}) => Promise<void>;
|
||||
/** بالاتر از مودال خلاصهٔ فعالیت */
|
||||
overlayZIndex?: number;
|
||||
}>();
|
||||
@@ -233,28 +237,35 @@ async function toggleVoiceNote() {
|
||||
}
|
||||
}
|
||||
|
||||
async function uploadQueue(items: Array<{ localId: string; name: string; file: File }>, drop: (localId: string) => void) {
|
||||
async function uploadQueue(
|
||||
items: Array<{ localId: string; name: string; file: File }>,
|
||||
drop: (localId: string) => void,
|
||||
): Promise<string[]> {
|
||||
const ids: string[] = [];
|
||||
for (const item of items) {
|
||||
const form = new FormData();
|
||||
form.append('file', item.file, item.name);
|
||||
await api.post(`/activities/${props.activity.id}/images`, form);
|
||||
const { data } = await api.post<{ id: string }>(`/activities/${props.activity.id}/images`, form);
|
||||
ids.push(data.id);
|
||||
drop(item.localId);
|
||||
uploadedCount.value += 1;
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
async function uploadPendingPhotos() {
|
||||
await uploadQueue([...pendingPhotos.value], (localId) => {
|
||||
async function uploadPendingPhotos(): Promise<string[]> {
|
||||
const photoIds = await uploadQueue([...pendingPhotos.value], (localId) => {
|
||||
pendingPhotos.value = pendingPhotos.value.filter((item) => item.localId !== localId);
|
||||
});
|
||||
await uploadQueue([...pendingVoices.value], (localId) => {
|
||||
const voiceIds = await uploadQueue([...pendingVoices.value], (localId) => {
|
||||
const voice = pendingVoices.value.find((item) => item.localId === localId);
|
||||
if (voice) URL.revokeObjectURL(voice.url);
|
||||
pendingVoices.value = pendingVoices.value.filter((item) => item.localId !== localId);
|
||||
});
|
||||
await uploadQueue([...pendingFiles.value], (localId) => {
|
||||
const fileIds = await uploadQueue([...pendingFiles.value], (localId) => {
|
||||
pendingFiles.value = pendingFiles.value.filter((item) => item.localId !== localId);
|
||||
});
|
||||
return [...photoIds, ...voiceIds, ...fileIds];
|
||||
}
|
||||
|
||||
async function submit() {
|
||||
@@ -268,11 +279,15 @@ async function submit() {
|
||||
pendingFiles.value.length > 0 ||
|
||||
uploadedCount.value > 0;
|
||||
try {
|
||||
await uploadPendingPhotos();
|
||||
await props.save({ text, photoOnly: hadPhoto && !text });
|
||||
const attachmentIds = await uploadPendingPhotos();
|
||||
await props.save({
|
||||
text,
|
||||
photoOnly: hadPhoto && !text,
|
||||
attachmentIds,
|
||||
});
|
||||
} catch (error) {
|
||||
photoError.value =
|
||||
pendingPhotos.value.length > 0
|
||||
pendingPhotos.value.length > 0 || pendingFiles.value.length > 0 || pendingVoices.value.length > 0
|
||||
? apiMessage(error, 'افزودن فایل ناموفق بود.')
|
||||
: apiMessage(error, 'ثبت نظر ناموفق بود.');
|
||||
} finally {
|
||||
|
||||
@@ -309,17 +309,35 @@ function apiMessage(e: unknown, fallback: string) {
|
||||
return fallback;
|
||||
}
|
||||
|
||||
function viewMedia(item: NoteMedia) {
|
||||
window.open(item.url, '_blank', 'noopener,noreferrer');
|
||||
}
|
||||
|
||||
function downloadMedia(item: NoteMedia) {
|
||||
const link = document.createElement('a');
|
||||
link.href = item.url;
|
||||
link.download = item.name || 'file';
|
||||
link.rel = 'noopener';
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
link.remove();
|
||||
}
|
||||
|
||||
async function loadNoteMedia(row: ActivityDto) {
|
||||
clearNoteMedia();
|
||||
const next: NoteMedia[] = [];
|
||||
for (const image of row.images ?? []) {
|
||||
const mime = image.mimeType.toLowerCase();
|
||||
const mime = (image.mimeType || 'application/octet-stream').toLowerCase();
|
||||
const kind = mime.startsWith('audio/') ? 'audio' : mime.startsWith('image/') ? 'image' : 'file';
|
||||
try {
|
||||
const { data } = await api.get<Blob>(`/activities/${row.id}/images/${image.id}`, {
|
||||
responseType: 'blob',
|
||||
});
|
||||
const url = URL.createObjectURL(data);
|
||||
const blob =
|
||||
data.type && data.type !== 'application/octet-stream' && !data.type.includes('json')
|
||||
? data
|
||||
: new Blob([data], { type: mime });
|
||||
const url = URL.createObjectURL(blob);
|
||||
if (props.activityId !== row.id) {
|
||||
URL.revokeObjectURL(url);
|
||||
continue;
|
||||
@@ -455,10 +473,14 @@ async function postponeTo(iso: string) {
|
||||
}
|
||||
}
|
||||
|
||||
async function submitComment(payload: { text: string; photoOnly: boolean }) {
|
||||
async function submitComment(payload: {
|
||||
text: string;
|
||||
photoOnly: boolean;
|
||||
attachmentIds?: string[];
|
||||
}) {
|
||||
const id = props.activityId;
|
||||
const row = activity.value;
|
||||
const body = payload.text.trim() || (payload.photoOnly ? 'عکس پیوست شد.' : '');
|
||||
const body = payload.text.trim() || (payload.photoOnly ? 'فایل پیوست شد.' : '');
|
||||
if (!id || !row || !body) return;
|
||||
saving.value = true;
|
||||
error.value = '';
|
||||
@@ -467,7 +489,9 @@ async function submitComment(payload: { text: string; photoOnly: boolean }) {
|
||||
const now = new Date();
|
||||
const author = auth.user?.fullName?.trim();
|
||||
const stamp = `[${formatJalaliNumeric(now)} ساعت ${formatClockFa(now)}${author ? ` — ${author}` : ''}]`;
|
||||
const entry = `${stamp}\n${body}`;
|
||||
const ids = [...new Set((payload.attachmentIds ?? []).filter(Boolean))];
|
||||
const attachLine = ids.length ? `\n[[attachments:${ids.join(',')}]]` : '';
|
||||
const entry = `${stamp}\n${body}${attachLine}`;
|
||||
await api.patch(`/activities/${id}`, { description: prev ? `${prev}\n\n${entry}` : entry });
|
||||
commentOpen.value = false;
|
||||
await load(id);
|
||||
@@ -597,11 +621,60 @@ function openFull() {
|
||||
:preview="{ zIndex: 1300 }"
|
||||
/>
|
||||
</a-flex>
|
||||
<a-flex
|
||||
v-if="entry.media.some((item) => item.kind === 'audio')"
|
||||
vertical
|
||||
:gap="8"
|
||||
:style="{ marginTop: '8px' }"
|
||||
>
|
||||
<audio
|
||||
v-for="voice in entry.media.filter((item) => item.kind === 'audio')"
|
||||
:key="voice.id"
|
||||
:src="voice.url"
|
||||
controls
|
||||
preload="metadata"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</a-flex>
|
||||
<a-flex
|
||||
v-if="entry.media.some((item) => item.kind === 'file')"
|
||||
vertical
|
||||
:gap="4"
|
||||
:style="{ marginTop: '8px' }"
|
||||
>
|
||||
<a-flex
|
||||
v-for="file in entry.media.filter((item) => item.kind === 'file')"
|
||||
:key="file.id"
|
||||
align="center"
|
||||
justify="space-between"
|
||||
:gap="8"
|
||||
wrap="wrap"
|
||||
>
|
||||
<a-typography-text>{{ file.name }}</a-typography-text>
|
||||
<a-space :size="4">
|
||||
<a-button type="link" @click="viewMedia(file)">مشاهده</a-button>
|
||||
<a-button type="link" @click="downloadMedia(file)">دانلود</a-button>
|
||||
</a-space>
|
||||
</a-flex>
|
||||
</a-flex>
|
||||
</div>
|
||||
<div v-for="image in threadBlocks.loose.filter((item) => item.kind === 'image')" :key="image.id" :style="noteBubbleStyle">
|
||||
<a-image :src="image.url" :alt="image.name" :width="72"
|
||||
:height="72" :preview="{ zIndex: 1300 }" />
|
||||
</div>
|
||||
<div
|
||||
v-for="file in threadBlocks.loose.filter((item) => item.kind === 'file')"
|
||||
:key="file.id"
|
||||
:style="noteBubbleStyle"
|
||||
>
|
||||
<a-flex align="center" justify="space-between" :gap="8" wrap="wrap">
|
||||
<a-typography-text>{{ file.name }}</a-typography-text>
|
||||
<a-space :size="4">
|
||||
<a-button type="link" @click="viewMedia(file)">مشاهده</a-button>
|
||||
<a-button type="link" @click="downloadMedia(file)">دانلود</a-button>
|
||||
</a-space>
|
||||
</a-flex>
|
||||
</div>
|
||||
</a-flex>
|
||||
<div v-else-if="plainNote || looseImages.length" :style="noteBubbleStyle">
|
||||
<a-typography-paragraph v-if="plainNote" :style="{ margin: 0, whiteSpace: 'pre-wrap' }">
|
||||
|
||||
@@ -865,16 +865,20 @@ async function loadActivityImages(row: ActivityDto) {
|
||||
clearImageUrls();
|
||||
const next: NoteMedia[] = [];
|
||||
for (const image of row.images ?? []) {
|
||||
const mime = image.mimeType.toLowerCase();
|
||||
const mime = (image.mimeType || 'application/octet-stream').toLowerCase();
|
||||
const kind = mime.startsWith('audio/') ? 'audio' : mime.startsWith('image/') ? 'image' : 'file';
|
||||
try {
|
||||
const { data } = await api.get<Blob>(`/activities/${row.id}/images/${image.id}`, {
|
||||
responseType: 'blob',
|
||||
});
|
||||
const blob =
|
||||
data.type && data.type !== 'application/octet-stream' && !data.type.includes('json')
|
||||
? data
|
||||
: new Blob([data], { type: mime });
|
||||
next.push({
|
||||
id: image.id,
|
||||
name: image.fileName,
|
||||
url: URL.createObjectURL(data),
|
||||
url: URL.createObjectURL(blob),
|
||||
kind,
|
||||
createdAt: image.createdAt,
|
||||
});
|
||||
@@ -885,6 +889,20 @@ async function loadActivityImages(row: ActivityDto) {
|
||||
imageUrls.value = next;
|
||||
}
|
||||
|
||||
function viewMedia(item: NoteMedia) {
|
||||
window.open(item.url, '_blank', 'noopener,noreferrer');
|
||||
}
|
||||
|
||||
function downloadMedia(item: NoteMedia) {
|
||||
const link = document.createElement('a');
|
||||
link.href = item.url;
|
||||
link.download = item.name || 'file';
|
||||
link.rel = 'noopener';
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
link.remove();
|
||||
}
|
||||
|
||||
|
||||
async function loadUsers() {
|
||||
try {
|
||||
@@ -1004,8 +1022,12 @@ async function postponeTo(iso: string) {
|
||||
}
|
||||
}
|
||||
|
||||
async function submitComment(payload: { text: string; photoOnly: boolean }) {
|
||||
const body = payload.text.trim() || (payload.photoOnly ? 'عکس پیوست شد.' : '');
|
||||
async function submitComment(payload: {
|
||||
text: string;
|
||||
photoOnly: boolean;
|
||||
attachmentIds?: string[];
|
||||
}) {
|
||||
const body = payload.text.trim() || (payload.photoOnly ? 'فایل پیوست شد.' : '');
|
||||
if (!id.value || !activity.value || !body) return;
|
||||
saving.value = true;
|
||||
error.value = '';
|
||||
@@ -1014,7 +1036,9 @@ async function submitComment(payload: { text: string; photoOnly: boolean }) {
|
||||
const now = new Date();
|
||||
const author = auth.user?.fullName?.trim();
|
||||
const stamp = `[${formatJalaliNumeric(now)} ساعت ${formatClockFa(now)}${author ? ` — ${author}` : ''}]`;
|
||||
const entry = `${stamp}\n${body}`;
|
||||
const ids = [...new Set((payload.attachmentIds ?? []).filter(Boolean))];
|
||||
const attachLine = ids.length ? `\n[[attachments:${ids.join(',')}]]` : '';
|
||||
const entry = `${stamp}\n${body}${attachLine}`;
|
||||
const next = prev ? `${prev}\n\n${entry}` : entry;
|
||||
await api.patch(`/activities/${id.value}`, { description: next });
|
||||
commentOpen.value = false;
|
||||
@@ -1663,7 +1687,11 @@ onUnmounted(() => {
|
||||
</div>
|
||||
<ul v-if="entry.media.some((image) => image.kind === 'file')" class="note-files">
|
||||
<li v-for="image in entry.media.filter((item) => item.kind === 'file')" :key="image.id">
|
||||
<a :href="image.url" :download="image.name">{{ image.name }}</a>
|
||||
<span class="note-file-name">{{ image.name }}</span>
|
||||
<span class="note-file-actions">
|
||||
<button type="button" class="note-file-btn" @click="viewMedia(image)">مشاهده</button>
|
||||
<button type="button" class="note-file-btn" @click="downloadMedia(image)">دانلود</button>
|
||||
</span>
|
||||
</li>
|
||||
</ul>
|
||||
</template>
|
||||
@@ -1746,7 +1774,11 @@ onUnmounted(() => {
|
||||
</div>
|
||||
<ul v-if="looseMedia.some((image) => image.kind === 'file')" class="note-files">
|
||||
<li v-for="image in looseMedia.filter((item) => item.kind === 'file')" :key="image.id">
|
||||
<a :href="image.url" :download="image.name">{{ image.name }}</a>
|
||||
<span class="note-file-name">{{ image.name }}</span>
|
||||
<span class="note-file-actions">
|
||||
<button type="button" class="note-file-btn" @click="viewMedia(image)">مشاهده</button>
|
||||
<button type="button" class="note-file-btn" @click="downloadMedia(image)">دانلود</button>
|
||||
</span>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
@@ -2677,8 +2709,35 @@ dd {
|
||||
gap: 0.35rem;
|
||||
}
|
||||
|
||||
.note-files a {
|
||||
.note-files li {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.note-file-name {
|
||||
color: #0f766e;
|
||||
font-weight: 600;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.note-file-actions {
|
||||
display: inline-flex;
|
||||
gap: 0.35rem;
|
||||
}
|
||||
|
||||
.note-file-btn {
|
||||
border: 1px solid #99f6e4;
|
||||
background: #fff;
|
||||
color: #0f766e;
|
||||
border-radius: 0.45rem;
|
||||
font: inherit;
|
||||
font-size: 0.85rem;
|
||||
font-weight: 700;
|
||||
padding: 0.2rem 0.55rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.dock {
|
||||
|
||||
Reference in New Issue
Block a user