refactor(static): split schedule and weather to modules
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { DataStorage } from "../base/storage";
|
||||
import { WeatherLocationElement } from "./component";
|
||||
import { Location } from "./model";
|
||||
|
||||
export class WeatherLocationManager {
|
||||
loadLocations(selector: string) {
|
||||
const locations = window.weatherLocationStorage.getAll();
|
||||
const container = document.querySelector(selector);
|
||||
if (container) {
|
||||
container.innerHTML = "";
|
||||
for (const location of locations) {
|
||||
const element = new WeatherLocationElement();
|
||||
element.setAttribute("location", JSON.stringify(location));
|
||||
element.setAttribute("removable", "");
|
||||
container.appendChild(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
weatherLocationStorage: DataStorage<Location>;
|
||||
weatherLocationManager: WeatherLocationManager;
|
||||
}
|
||||
}
|
||||
|
||||
window.weatherLocationStorage = new DataStorage("weather:locations");
|
||||
window.weatherLocationManager = new WeatherLocationManager();
|
||||
Reference in New Issue
Block a user