From 43355ffc97ea5b6d2b7edcd9fc2e817a98d515e6 Mon Sep 17 00:00:00 2001 From: gabe Date: Tue, 27 Feb 2024 10:10:09 -0500 Subject: [PATCH] feat(frontend): use sites.json as site name mapping --- public/script.js | 79 +++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 44 deletions(-) diff --git a/public/script.js b/public/script.js index 5793c89..edba232 100644 --- a/public/script.js +++ b/public/script.js @@ -1,51 +1,42 @@ let propertiesObject = {}; let propertiesDiv = document.getElementsByClassName("properties"); -const sites = { - "https://ygl.is/leigha-emery-1": "Leigha", - "https://ygl.is/99334": "Denis", - "https://ygl.is/99333": "Nick", - "https://ygl.is/99331": "Orysya", - "https://ygl.is/listch": "Litsch", - "https://ygl.is/chris-liu": "Chris", - "https://ygl.is/keith-rose": "Keith", - "https://ygl.is/92567": "Michael", - "https://ygl.is/Alexis-Velez-1": "Alexis", - "https://ygl.is/alexandra-mishenina": "Alexandra", -}; - -fetch("https://ygl.dabe.tech/listings") +fetch("../data/sites.json") .then((response) => response.json()) - .then((json) => { - propertiesObject = json; - // console.log(propertiesObject); - let i = 0; - - Object.entries(propertiesObject).forEach((property) => { - let listingInfo = property[1]; - - let nameTags = ""; - // find which sites the listing is from and store the names - for (let j = 0; j < listingInfo.refs.length; j++) { - // for each link, get the value associated with the key (the name) - let link = listingInfo.refs[j]; - let nameLink = link.split("/rental")[0]; - let name = sites[nameLink]; - - // build the link to the site around the name ( tag) - nameTags += `${name}\u00A0\u00A0`; - } - - // - const p = $(".properties").append( - `

$${listingInfo.price} \u00A0\u00A0\u00A0 ${listingInfo.beds}Bd / ${listingInfo.baths}bth - \u00A0\u00A0\u00A0 ${property[0]}: \u00A0\u00A0\u00A0 ${nameTags}

- - ` - ); - i++; - }); - }); + .then((sites) => { + fetch("https://ygl.dabe.tech/listings") + .then((response) => response.json()) + .then((json) => { + propertiesObject = json; + // console.log(propertiesObject); + let i = 0; + + Object.entries(propertiesObject).forEach((property) => { + let listingInfo = property[1]; + + let nameTags = ""; + // find which sites the listing is from and store the names + for (let j = 0; j < listingInfo.refs.length; j++) { + // for each link, get the value associated with the key (the name) + let link = listingInfo.refs[j]; + let nameLink = link.split("/rental")[0]; + let name = sites[nameLink]; + + // build the link to the site around the name ( tag) + nameTags += `${name}\u00A0\u00A0`; + } + + // + const p = $(".properties").append( + `

$${listingInfo.price} \u00A0\u00A0\u00A0 ${listingInfo.beds}Bd / ${listingInfo.baths}bth + \u00A0\u00A0\u00A0 ${property[0]}: \u00A0\u00A0\u00A0 ${nameTags}

+ + ` + ); + i++; + }); + }); + }) // $().add(`

${property[0]}

`); // console.log($());`