Skip to content

Commit

Permalink
feat(frontend): use sites.json as site name mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
gabeklavans committed Feb 27, 2024
1 parent 2bf7314 commit 43355ff
Showing 1 changed file with 35 additions and 44 deletions.
79 changes: 35 additions & 44 deletions public/script.js
Original file line number Diff line number Diff line change
@@ -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 (<a> tag)
nameTags += `<a href=${link} target="_blank">${name}</a>\u00A0\u00A0`;
}

//
const p = $(".properties").append(
`<p id="listing${i}" class="listing"> <span class="price">$${listingInfo.price} </span> \u00A0\u00A0\u00A0 <span class="beds-baths"> ${listingInfo.beds}Bd / ${listingInfo.baths}bth </span>
\u00A0\u00A0\u00A0 <span class="address">${property[0]}:</span> \u00A0\u00A0\u00A0 <span class="name-tags">${nameTags} </span> </p>
<input type="text id="listing-notes" name="notes">`
);
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 (<a> tag)
nameTags += `<a href=${link} target="_blank">${name}</a>\u00A0\u00A0`;
}

//
const p = $(".properties").append(
`<p id="listing${i}" class="listing"> <span class="price">$${listingInfo.price} </span> \u00A0\u00A0\u00A0 <span class="beds-baths"> ${listingInfo.beds}Bd / ${listingInfo.baths}bth </span>
\u00A0\u00A0\u00A0 <span class="address">${property[0]}:</span> \u00A0\u00A0\u00A0 <span class="name-tags">${nameTags} </span> </p>
<input type="text id="listing-notes" name="notes">`
);
i++;
});
});
})

// $().add(`<p> ${property[0]} </p>`);
// console.log($());`
Expand Down

0 comments on commit 43355ff

Please sign in to comment.