44 {{ errorMessage }}
55 </div >
66 <button
7- role =" button"
8- aria-label =" Toggle favorite"
97 class =" action-button"
108 :class =" { 'is-favorite': isFavorite }"
119 :data-favorite =" isFavorite"
10+ role =" button"
11+ aria-label =" Toggle favorite"
1212 @click.prevent =" toggleFavorite(painting.item)"
1313 >
1414 <svg
2323 />
2424 </svg >
2525 </button >
26- <g-link class =" action-button" :to =" computeWikidataLink " >
26+ <g-link class =" action-button" :to =" getWikidataLink " >
2727 <svg
2828 xmlns =" http://www.w3.org/2000/svg"
2929 width =" 24"
3737 </svg >
3838 </g-link >
3939 <button
40+ class =" action-button"
4041 role =" button"
4142 aria-label =" Download image"
42- class =" action-button"
4343 @click.prevent =" download()"
4444 >
4545 <svg
@@ -62,6 +62,9 @@ import FileSaver from "file-saver";
6262
6363import { TOGGLE_FAVORITE } from " ~/components/js/Event.js" ;
6464
65+ // Error timeout matches CSS variable --error-timeout: 3000ms
66+ const ERROR_TIMEOUT = 3000 ;
67+
6568export default {
6669 props: {
6770 painting: {
@@ -77,10 +80,10 @@ export default {
7780 },
7881 computed: {
7982 /**
80- * Computes the Wikidata URL for the current painting
83+ * Gets the Wikidata URL for the current painting
8184 * @returns {string} The full Wikidata URL
8285 */
83- computeWikidataLink : function () {
86+ getWikidataLink () {
8487 return " https://www.wikidata.org/wiki/" + this .painting .item ;
8588 }
8689 },
@@ -97,28 +100,27 @@ export default {
97100 * Downloads the painting image
98101 * Handles error cases and displays user-friendly error messages
99102 */
100- download : function () {
103+ download () {
101104 // Reset error message
102105 this .errorMessage = null ;
103106
104107 // In Gridsome, image is a string URL, not an object
105108 let imageUrl = this .painting .image || this .painting .cover_image ;
106109 if (! imageUrl) {
107110 this .errorMessage = " Image not available for download" ;
108- // Show error message to user (could be enhanced with a toast notification)
109111 setTimeout (() => {
110112 this .errorMessage = null ;
111- }, 3000 ); // var(--error-timeout) - 3000ms
113+ }, ERROR_TIMEOUT );
112114 return ;
113115 }
114116 // Handle both string URLs and image objects
115117 let uri =
116118 typeof imageUrl === " string" ? imageUrl : imageUrl .src || imageUrl;
117119 if (! uri) {
118- this .errorMessage = " Invalid image URL" ;
120+ this .errorMessage = " Invalid image URL. Unable to download. " ;
119121 setTimeout (() => {
120122 this .errorMessage = null ;
121- }, 3000 ); // var(--error-timeout) - 3000ms
123+ }, ERROR_TIMEOUT );
122124 return ;
123125 }
124126 try {
@@ -128,10 +130,10 @@ export default {
128130 filename = decodeURI (filename).replace (/ %2C/ g , " ," );
129131 FileSaver .saveAs (uri, filename);
130132 } catch {
131- this .errorMessage = " Failed to download image" ;
133+ this .errorMessage = " Failed to download image. Please try again. " ;
132134 setTimeout (() => {
133135 this .errorMessage = null ;
134- }, 3000 ); // var(--error-timeout) - 3000ms
136+ }, ERROR_TIMEOUT );
135137 }
136138 }
137139 }
0 commit comments