Skip to content

Commit 665c892

Browse files
authored
feat: add option to open assets as link instead of forcing download (#1359)
- Updated `downloadAsset` function to include a new `asLink` parameter. - Enabled assets to be opened in a new tab when `asLink` is true. - Updated relevant UI interactions (`@click-pdf`, `@click`, and `base-button`) to utilize the new `asLink` behavior. These changes provide the option for users to view assets in their browser without forcing a download.
1 parent fb0a441 commit 665c892

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/pages/unauthenticated/disasters/DisasterDetail.vue

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function getAniIncident(phoneNumber: number | string) {
8686
return matchingAniIncident ?? incident.value;
8787
}
8888
89-
const downloadAsset = async (asset: IncidentAniAsset) => {
89+
const downloadAsset = async (asset: IncidentAniAsset, asLink = false) => {
9090
// refetch assets before downloading so that they don't have expired link
9191
// in case user's been on the page for a while
9292
try {
@@ -104,13 +104,20 @@ const downloadAsset = async (asset: IncidentAniAsset) => {
104104
asset = matchingAsset;
105105
}
106106
}
107-
const response = await axios.get(asset.files[0].general_file_url, {
108-
responseType: 'blob',
109-
headers: {
110-
Authorization: null,
111-
},
112-
});
113-
forceFileDownload(response, asset.files[0].filename);
107+
108+
if (asLink) {
109+
// Open the link directly in a new tab
110+
window.open(asset.files[0].general_file_url, '_blank');
111+
} else {
112+
// Force file download
113+
const response = await axios.get(asset.files[0].general_file_url, {
114+
responseType: 'blob',
115+
headers: {
116+
Authorization: null,
117+
},
118+
});
119+
forceFileDownload(response, asset.files[0].filename);
120+
}
114121
} catch (error) {
115122
getErrorMessage(error);
116123
}
@@ -222,14 +229,14 @@ onMounted(async () => {
222229
"
223230
:pdf="asset.files[0]"
224231
:show-download-button="false"
225-
@click-pdf="() => downloadAsset(asset)"
232+
@click-pdf="() => downloadAsset(asset, true)"
226233
/>
227234
<img
228235
v-else
229236
:src="asset.files[0].general_file_url"
230237
:alt="asset.files[0].filename"
231238
class="h-64 max-w-84"
232-
@click="() => downloadAsset(asset)"
239+
@click="() => downloadAsset(asset, true)"
233240
/>
234241
<div class="flex mt-2 items-center justify-center gap-2">
235242
<div class="flex gap-5 items-center">
@@ -239,7 +246,7 @@ onMounted(async () => {
239246
/>
240247
<div class="flex justify-self-end">
241248
<base-button
242-
:action="() => downloadAsset(asset)"
249+
:action="() => downloadAsset(asset, true)"
243250
variant="solid"
244251
:text="$t('actions.download')"
245252
:alt="$t('actions.download')"

0 commit comments

Comments
 (0)