diff --git a/assets/js/components/SiteAnalysisResult.js b/assets/js/components/SiteAnalysisResult.js
index 1709d286..af66a8f0 100644
--- a/assets/js/components/SiteAnalysisResult.js
+++ b/assets/js/components/SiteAnalysisResult.js
@@ -39,6 +39,7 @@ class SiteAnalysisResult {
async _init() {
const urlParams = new URLSearchParams(window.location.search);
const langSwitchersElements = document.querySelectorAll(".language-switcher a.lang")
+ const screenshotImgElement = document.querySelector(".result-screenshot")
let pageResultData = {};
@@ -47,6 +48,11 @@ class SiteAnalysisResult {
if (urlParams.has("url") && urlParams.has("size") && urlParams.has("ges")) {
for (const [key, value] of urlParams.entries()) {
pageResultData[key] = value;
+
+ if (key === "id") {
+ const screenshotUrl = AnalysisService.fetchAnalysisScreenshotUrlById(urlParams.get("id"))
+ screenshotImgElement.setAttribute("src", screenshotUrl)
+ }
}
// update the link URL of every lang switcher
@@ -58,13 +64,17 @@ class SiteAnalysisResult {
// else fetch analysis result from id
// NOTE : url params example to test : "?id=ec839aca-7c12-42e8-8541-5f7f94c36b7f
} else if (urlParams.has("id")) {
- const id = urlParams.get("id");
+ const analysisId = urlParams.get("id");
+
// window.location.pathname is something like /resultat (in french) or /en/result (in english)
- pageResultData = await AnalysisService.fetchAnalysisById(id, window.location.pathname);
+ pageResultData = await AnalysisService.fetchAnalysisById(analysisId, window.location.pathname)
+
+ const screenshotUrl = AnalysisService.fetchAnalysisScreenshotUrlById(analysisId)
+ screenshotImgElement.setAttribute("src", screenshotUrl)
// update the link URL of every lang switcher
langSwitchersElements.forEach((a) => {
- const href = a.getAttribute("href") + "?id=" + id
+ const href = a.getAttribute("href") + "?id=" + analysisId
a.setAttribute("href", href)
})
} else {
diff --git a/assets/js/services/AnalysisService.js b/assets/js/services/AnalysisService.js
index ca20752e..050dfb0c 100644
--- a/assets/js/services/AnalysisService.js
+++ b/assets/js/services/AnalysisService.js
@@ -56,6 +56,14 @@ class AnalysisService {
}
}
+ /**
+ * @param {string} id
+ * @returns {string}
+ */
+ fetchAnalysisScreenshotUrlById(id) {
+ return ApiService.fetchAnalysisScreenshotUrlById(id)
+ }
+
/**
*
* @param {string} id
diff --git a/assets/js/services/ApiService.js b/assets/js/services/ApiService.js
index b04edc51..30ebcdf7 100644
--- a/assets/js/services/ApiService.js
+++ b/assets/js/services/ApiService.js
@@ -1,34 +1,36 @@
import ky from "ky";
+const BASE_URL = "https://api.ecoindex.fr/v1/"
+const BROWSER_WIDTH = 1920
+const BROWSER_HEIGHT = 1080;
+
class ApiService {
#controller = null;
- #baseURL = "https://api.ecoindex.fr/v1/";
- #browserWidth = 1920;
- #browserHeight = 1080;
/**
* Create a new analysis task by URL
*
* @param {string} url URL
- * @returns {Response} response object
+ * @returns {Promise