Skip to content

Commit bc95b52

Browse files
authored
Chat: update File Attachments jQuery demo (#31664)
1 parent 1d503db commit bc95b52

File tree

7 files changed

+40
-39
lines changed

7 files changed

+40
-39
lines changed

apps/demos/Demos/Chat/FileAttachments/jQuery/data.js

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,41 +16,41 @@ const supportAgent = {
1616
avatarUrl: '../../../../images/petersmith.png',
1717
};
1818

19-
const createEmptyAttachment = (name, type) => {
20-
const blob = new Blob([''], { type });
21-
const url = URL.createObjectURL(blob);
22-
23-
return {
24-
name,
25-
url,
26-
size: 1024 * 10,
27-
};
28-
};
29-
30-
const screenshot1 = createEmptyAttachment('Screenshot1.jpg', 'image/jpeg');
31-
const screenshot2 = createEmptyAttachment('Screenshot2.jpg', 'image/jpeg');
32-
const screenshot3 = createEmptyAttachment('Screenshot3.jpg', 'image/jpeg');
33-
const instructions = createEmptyAttachment('Instructions.pdf', 'application/pdf');
34-
3519
const messages = [
36-
{
37-
id: new DevExpress.data.Guid(),
38-
timestamp: getTimestamp(date, -9),
39-
author: supportAgent,
40-
text: 'Hello, John!\nHow can I assist you today?',
41-
},
4220
{
4321
id: new DevExpress.data.Guid(),
4422
timestamp: getTimestamp(date, -7),
4523
author: currentUser,
46-
text: "Hi, I'm having trouble accessing my account.\nIt says my password is incorrect. I’ve attached some screenshots for you to check.",
47-
attachments: [screenshot1, screenshot2, screenshot3],
24+
text: "Hi! I'm having trouble accessing my account.\nThe website says my password is incorrect. I'm sending a few screenshots so you can see where I get the error.",
25+
attachments: [
26+
{
27+
name: 'Pic1.png',
28+
url: '../../../../images/Chat/FileAttachments/Pic1.png',
29+
size: 1024 * 10,
30+
},
31+
{
32+
name: 'Pic2.png',
33+
url: '../../../../images/Chat/FileAttachments/Pic2.png',
34+
size: 1024 * 10,
35+
},
36+
{
37+
name: 'Pic3.png',
38+
url: '../../../../images/Chat/FileAttachments/Pic3.png',
39+
size: 1024 * 10,
40+
},
41+
],
4842
},
4943
{
5044
id: new DevExpress.data.Guid(),
5145
timestamp: getTimestamp(date, -7),
5246
author: supportAgent,
53-
text: 'Thanks for the screenshots! I can help you with that. Please refer to the attached file for instructions to restore access.',
54-
attachments: [instructions],
47+
text: 'Hello! Thanks for including screenshots. To restore access, please follow instructions in the attached file.\nLet me know if you need anything else.',
48+
attachments: [
49+
{
50+
name: 'Instructions.pdf',
51+
url: '../../../../images/Chat/FileAttachments/Instructions.pdf',
52+
size: 1024 * 10,
53+
},
54+
],
5555
},
5656
];

apps/demos/Demos/Chat/FileAttachments/jQuery/index.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,29 @@ $(() => {
1515

1616
const uploadedFilesMap = new Map();
1717

18+
function getFileUrl(filename) {
19+
return uploadedFilesMap.get(filename);
20+
}
21+
1822
$('#chat').dxChat({
1923
height: 600,
2024
dataSource,
2125
reloadOnChange: false,
2226
user: currentUser,
2327
fileUploaderOptions: {
2428
uploadFile: () => {},
25-
onValueChanged(e) {
26-
e.value.forEach((file) => {
27-
const url = URL.createObjectURL(file);
28-
uploadedFilesMap.set(file.name, url);
29-
});
29+
onUploaded({ file }) {
30+
const url = URL.createObjectURL(file);
31+
uploadedFilesMap.set(file.name, url);
3032
},
3133
},
3234
onMessageEntered(e) {
3335
const { message } = e;
3436

35-
const attachmentsWithUrls = message.attachments?.map((attachment) => {
36-
const url = uploadedFilesMap.get(attachment.name);
37-
return { ...attachment, url };
38-
});
37+
const attachmentsWithUrls = message.attachments?.map((attachment) => ({
38+
...attachment,
39+
url: getFileUrl(attachment.name),
40+
}));
3941

4042
dataSource.store().push([{
4143
type: 'insert',
@@ -54,12 +56,11 @@ $(() => {
5456
}
5557

5658
const link = document.createElement('a');
57-
link.href = attachment.url;
58-
link.download = attachment.name;
59-
document.body.appendChild(link);
59+
link.setAttribute('href', attachment.url);
60+
link.setAttribute('download', attachment.name);
6061

62+
document.body.appendChild(link);
6163
link.click();
62-
6364
document.body.removeChild(link);
6465
},
6566
}).dxChat('instance');
12.7 KB
Binary file not shown.
5.71 KB
Loading
5.94 KB
Loading
6.04 KB
Loading
356 Bytes
Loading

0 commit comments

Comments
 (0)