Removing not neccesary files.

Using same bundler as template project.
This commit is contained in:
2023-02-25 12:07:54 +01:00
parent c9bb903cf4
commit 3b4a0e4ffc
38 changed files with 144 additions and 874 deletions

View File

@ -1,45 +0,0 @@
import Location from "../Location.js";
import Event from "../Event.js";
import GithubLocations from "./GithubLocations.js";
import Locations from "../Locations.js";
export default class App {
constructor() {
this._init();
}
_init() {
this.githubLocations = new GithubLocations('Midefos', 'idealista-enhancer');
}
async load() {
const newLocation = document.querySelector('textarea#newLocation');
newLocation.textContent = JSON.stringify(Location.empty(), undefined, 4);
const locations = await this.githubLocations.extractLocations();
const locationQuantity = document.querySelector('#locations-quantity');
locationQuantity.textContent = locations.length;
const tableBody = document.querySelector('#locations-table tbody');
for (const location of locations) {
tableBody.insertAdjacentHTML('afterend', `<tr>
<td>${location.name}</td>
<td><a data-name="${location.name}" class="load-location waves-effect waves-light btn">Cargar</a></td>
</tr>`);
}
Event.click('.load-location', async (element) => {
const rawName = element.getAttribute('data-name');
const name = rawName.substring(0, rawName.indexOf('.json'));
const location = await Locations.get(name);
document.querySelector('#locationFilename').value = name;
newLocation.textContent = JSON.stringify(location, undefined, 4);
})
}
}
const app = new App();
app.load()

View File

@ -1,40 +0,0 @@
export default class GithubLocations {
constructor(user, repo) {
this.user = user;
this.repo = repo;
}
get mainUrl() {
return `https://api.github.com/repos/${this.user}/${this.repo}/git/trees/main`
}
async extractLocations() {
const locationTreeInfo = await this._extractLocationTreeData();
const data = await fetch(locationTreeInfo.url);
const json = await data.json();
const locations = [];
for (const treeInfo of json.tree) {
locations.push({ name: treeInfo.path, url: treeInfo.url });
}
return locations;
}
async _extractLocationTreeData() {
const data = await fetch(this.mainUrl);
const json = await data.json();
console.log(json)
for (const treeInfo of json.tree) {
if (treeInfo.path === 'locations') {
return treeInfo;
}
}
}
}