From b1b100cc93b8f958e5b3d233d216f8953b3cdd87 Mon Sep 17 00:00:00 2001 From: toduyemi Date: Tue, 16 Apr 2024 00:31:27 -0400 Subject: [PATCH] Deploy to gh --- components/app.js | 33 ++++ components/app.js.map | 1 + components/autocomplete.js | 59 +++++++ components/autocomplete.js.map | 1 + components/current-weather.js | 26 +++ components/current-weather.js.map | 1 + components/daily-forecast.js | 28 +++ components/daily-forecast.js.map | 1 + components/dataCharts.js | 215 +++++++++++++++++++++++ components/dataCharts.js.map | 1 + components/date-time.js | 10 ++ components/date-time.js.map | 1 + components/highlights.js | 29 ++++ components/highlights.js.map | 1 + helpers/apiHelpers.js | 58 +++++++ helpers/apiHelpers.js.map | 1 + helpers/beaufort.js | 29 ++++ helpers/beaufort.js.map | 1 + helpers/dataHelpers.js | 101 +++++++++++ helpers/dataHelpers.js.map | 1 + helpers/helpers.js | 50 ++++++ helpers/helpers.js.map | 1 + index.js | 10 ++ index.js.map | 1 + openWeatherIcons.json | 272 ++++++++++++++++++++++++++++++ types/appTypes.types.js | 25 +++ types/appTypes.types.js.map | 1 + types/geoDB.types.js | 3 + types/geoDB.types.js.map | 1 + types/openWeather.types.js | 3 + types/openWeather.types.js.map | 1 + utilities/apiUtilities.js | 23 +++ utilities/apiUtilities.js.map | 1 + utilities/dataUtils.js | 52 ++++++ utilities/dataUtils.js.map | 1 + utilities/typeUtility.js | 8 + utilities/typeUtility.js.map | 1 + 37 files changed, 1052 insertions(+) create mode 100644 components/app.js create mode 100644 components/app.js.map create mode 100644 components/autocomplete.js create mode 100644 components/autocomplete.js.map create mode 100644 components/current-weather.js create mode 100644 components/current-weather.js.map create mode 100644 components/daily-forecast.js create mode 100644 components/daily-forecast.js.map create mode 100644 components/dataCharts.js create mode 100644 components/dataCharts.js.map create mode 100644 components/date-time.js create mode 100644 components/date-time.js.map create mode 100644 components/highlights.js create mode 100644 components/highlights.js.map create mode 100644 helpers/apiHelpers.js create mode 100644 helpers/apiHelpers.js.map create mode 100644 helpers/beaufort.js create mode 100644 helpers/beaufort.js.map create mode 100644 helpers/dataHelpers.js create mode 100644 helpers/dataHelpers.js.map create mode 100644 helpers/helpers.js create mode 100644 helpers/helpers.js.map create mode 100644 index.js create mode 100644 index.js.map create mode 100644 openWeatherIcons.json create mode 100644 types/appTypes.types.js create mode 100644 types/appTypes.types.js.map create mode 100644 types/geoDB.types.js create mode 100644 types/geoDB.types.js.map create mode 100644 types/openWeather.types.js create mode 100644 types/openWeather.types.js.map create mode 100644 utilities/apiUtilities.js create mode 100644 utilities/apiUtilities.js.map create mode 100644 utilities/dataUtils.js create mode 100644 utilities/dataUtils.js.map create mode 100644 utilities/typeUtility.js create mode 100644 utilities/typeUtility.js.map diff --git a/components/app.js b/components/app.js new file mode 100644 index 0000000..f741a19 --- /dev/null +++ b/components/app.js @@ -0,0 +1,33 @@ +import { url } from '../helpers/apiHelpers'; +import { fetchData } from '../utilities/apiUtilities'; +import { createForecastArr, parse5DayForecast, parseCurrentWeather, } from '../helpers/dataHelpers'; +import { parseUnitState } from '../helpers/helpers'; +import { renderWeather, renderConditionsTitle } from './current-weather'; +import { renderDailyCards } from './daily-forecast'; +import { renderChart } from './dataCharts'; +import { renderQueryTitle } from './date-time'; +import { renderHighlights } from './highlights'; +export async function refreshPage(coord, unitFlag) { + const unitState = parseUnitState(unitFlag); + const unitUrl = url.units(unitState); + const responseFore = await fetchData({ + url: url.forecast(coord), + units: unitUrl, + }); + const responseWeath = await fetchData({ + url: url.weather(coord), + units: unitUrl, + }); + const forecastArr = createForecastArr(responseFore); + renderChart(forecastArr, unitState); + const daily = parse5DayForecast(forecastArr); + const today = parseCurrentWeather(responseWeath, responseFore); + if (coord.country) { + renderWeather(today, coord.country, unitState); + } + renderConditionsTitle(today); + renderHighlights(today, unitState); + renderQueryTitle(today); + renderDailyCards(daily, unitState); +} +//# sourceMappingURL=app.js.map \ No newline at end of file diff --git a/components/app.js.map b/components/app.js.map new file mode 100644 index 0000000..b1e663f --- /dev/null +++ b/components/app.js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AAG,mBAAmB,CAAC,aAAa,EAAE,YAAY,CAAC,CAAC;IAC/D,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;QAClB,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IACjD,CAAC;IACD,qBAAqB,CAAC,KAAK,CAAC,CAAC;IAC7B,gBAAgB,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IACnC,gBAAgB,CAAC,KAAK,CAAC,CAAC;IACxB,gBAAgB,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;AACrC,CAAC"} \ No newline at end of file diff --git a/components/autocomplete.js b/components/autocomplete.js new file mode 100644 index 0000000..f2f32af --- /dev/null +++ b/components/autocomplete.js @@ -0,0 +1,59 @@ +//@ts-ignore +import { autocomplete } from '@algolia/autocomplete-js'; +import { refreshPage } from './app'; +import { fetchCities } from '../helpers/apiHelpers'; +import { getElement } from '../utilities/typeUtility'; +function debouncePromise(fn, time) { + let timerId = undefined; + return function debounced(...args) { + if (timerId) { + clearTimeout(timerId); + } + return new Promise((resolve) => { + timerId = setTimeout(() => resolve(fn(...args)), time); + }); + }; +} +const debounced = debouncePromise((items) => Promise.resolve(items), 1100); +export async function autoSearch() { + //observe the unit Toggle + let currentCoord; + const unitToggle = getElement('#unit-toggle', HTMLInputElement); + unitToggle.addEventListener('change', (e) => { + if (currentCoord) { + refreshPage(currentCoord, unitToggle.checked); + } + }); + autocomplete({ + container: '#search-form', + placeholder: 'Location/City...', + getSources() { + return debounced([ + { + sourceId: 'cities', + getItems({ query }) { + return fetchCities(query); + }, + getItemInputValue({ item }) { + return `${item.label.name}, ${item.label.region} - ${item.label.country}`; + }, + templates: { + item({ item }) { + return `${item.label.name}, ${item.label.region} - ${item.label.countryCode}`; + }, + }, + onSelect({ item }) { + //update state of current place of interest + currentCoord = { + lat: item.coord.lat, + lon: item.coord.lon, + country: item.label.country, + }; + refreshPage(currentCoord, unitToggle.checked); + }, + }, + ]); + }, + }); +} +//# sourceMappingURL=autocomplete.js.map \ No newline at end of file diff --git a/components/autocomplete.js.map b/components/autocomplete.js.map new file mode 100644 index 0000000..8a9e973 --- /dev/null +++ b/components/autocomplete.js.map @@ -0,0 +1 @@ +{"version":3,"file":"autocomplete.js","sourceRoot":"","sources":["../../src/components/autocomplete.ts"],"names":[],"mappings":"AAAA,YAAY;AACZ,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAGxD,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEpD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD,SAAS,eAAe,CACtB,EAAoC,EACpC,IAAY;IAEZ,IAAI,OAAO,GAA8C,SAAS,CAAC;IAEnE,OAAO,SAAS,SAAS,CAAC,GAAG,IAAa;QACxC,IAAI,OAAO,EAAE,CAAC;YACZ,YAAY,CAAC,OAAO,CAAC,CAAC;QACxB,CAAC;QACD,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;YACnC,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;QACzD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,SAAS,GAAG,eAAe,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,CAAC;AAE3E,MAAM,CAAC,KAAK,UAAU,UAAU;IAC9B,yBAAyB;IACzB,IAAI,YAAyB,CAAC;IAC9B,MAAM,UAAU,GAAG,UAAU,CAAC,cAAc,EAAE,gBAAgB,CAAC,CAAC;IAEhE,UAAU,CAAC,gBAAgB,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE;QAC1C,IAAI,YAAY,EAAE,CAAC;YACjB,WAAW,CAAC,YAAY,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC;QAChD,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,YAAY,CAAC;QACX,SAAS,EAAE,cAAc;QACzB,WAAW,EAAE,kBAAkB;QAC/B,UAAU;YACR,OAAO,SAAS,CAAC;gBACf;oBACE,QAAQ,EAAE,QAAQ;oBAClB,QAAQ,CAAC,EAAE,KAAK,EAAqB;wBACnC,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC;oBAC5B,CAAC;oBACD,iBAAiB,CAAC,EAAE,IAAI,EAAuB;wBAC7C,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,KAAK,CAAC,MAAM,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;oBAC5E,CAAC;oBACD,SAAS,EAAE;wBACT,IAAI,CAAC,EAAE,IAAI,EAAuB;4BAChC,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,KAAK,CAAC,MAAM,MAAM,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;wBAChF,CAAC;qBACF;oBACD,QAAQ,CAAC,EAAE,IAAI,EAAuB;wBACpC,2CAA2C;wBAC3C,YAAY,GAAG;4BACb,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG;4BACnB,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG;4BACnB,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO;yBAC5B,CAAC;wBACF,WAAW,CAAC,YAAY,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC;oBAChD,CAAC;iBACF;aACF,CAEA,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;AACL,CAAC"} \ No newline at end of file diff --git a/components/current-weather.js b/components/current-weather.js new file mode 100644 index 0000000..efae3fe --- /dev/null +++ b/components/current-weather.js @@ -0,0 +1,26 @@ +import { iconPath } from '../helpers/apiHelpers'; +import { printTempUnit } from '../helpers/helpers'; +import { getElement } from '../utilities/typeUtility'; +export function renderWeather(current, country, unitState) { + const template = getElement('#weather-template', HTMLTemplateElement); + const currentCard = document.importNode(template.content, true); + currentCard.querySelector('#location').textContent = `${current.name}, \r\n`; + currentCard.querySelector('#location').textContent += `${country}`; + const weatherIcon = new Image(); + weatherIcon.src = iconPath + `${current.weather_icon}.svg`; + currentCard.querySelector('#temp-output').innerHTML = + `${current.temp}` + printTempUnit(unitState); + currentCard.querySelector('#icon-ctr').prepend(weatherIcon); + currentCard.querySelector('#feels-like').innerHTML = + `${current.feels_like}` + printTempUnit(unitState); + // today.appendChild(dailyCard); + document.querySelector('#current-ctr')?.replaceChildren(currentCard); +} +export function renderConditionsTitle(current) { + const template = getElement('#current-template', HTMLTemplateElement); + const currentCard = document.importNode(template.content, true); + currentCard.querySelector('#description-output').textContent = + current.weather_condition; + getElement('#current-conditions', HTMLElement).replaceChildren(currentCard); +} +//# sourceMappingURL=current-weather.js.map \ No newline at end of file diff --git a/components/current-weather.js.map b/components/current-weather.js.map new file mode 100644 index 0000000..bca62fd --- /dev/null +++ b/components/current-weather.js.map @@ -0,0 +1 @@ +{"version":3,"file":"current-weather.js","sourceRoot":"","sources":["../../src/components/current-weather.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAGtD,MAAM,UAAU,aAAa,CAC3B,OAAoB,EACpB,OAAe,EACf,SAAgB;IAEhB,MAAM,QAAQ,GAAwB,UAAU,CAC9C,mBAAmB,EACnB,mBAAmB,CACpB,CAAC;IAEF,MAAM,WAAW,GAAG,QAAQ,CAAC,UAAU,CAAC,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAChE,WAAW,CAAC,aAAa,CAAC,WAAW,CAAE,CAAC,WAAW,GAAG,GAAG,OAAO,CAAC,IAAI,QAAQ,CAAC;IAC9E,WAAW,CAAC,aAAa,CAAC,WAAW,CAAE,CAAC,WAAW,IAAI,GAAG,OAAO,EAAE,CAAC;IACpE,MAAM,WAAW,GAAG,IAAI,KAAK,EAAE,CAAC;IAChC,WAAW,CAAC,GAAG,GAAG,QAAQ,GAAG,GAAG,OAAO,CAAC,YAAY,MAAM,CAAC;IAE3D,WAAW,CAAC,aAAa,CAAC,cAAc,CAAE,CAAC,SAAS;QAClD,GAAG,OAAO,CAAC,IAAI,EAAE,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC;IAC/C,WAAW,CAAC,aAAa,CAAC,WAAW,CAAE,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAE7D,WAAW,CAAC,aAAa,CAAC,aAAa,CAAE,CAAC,SAAS;QACjD,GAAG,OAAO,CAAC,UAAU,EAAE,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC;IAErD,kCAAkC;IAElC,QAAQ,CAAC,aAAa,CAAC,cAAc,CAAC,EAAE,eAAe,CAAC,WAAW,CAAC,CAAC;AACvE,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,OAAoB;IACxD,MAAM,QAAQ,GAAwB,UAAU,CAC9C,mBAAmB,EACnB,mBAAmB,CACpB,CAAC;IAEF,MAAM,WAAW,GAAG,QAAQ,CAAC,UAAU,CAAC,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAChE,WAAW,CAAC,aAAa,CAAC,qBAAqB,CAAE,CAAC,WAAW;QAC3D,OAAO,CAAC,iBAAiB,CAAC;IAE5B,UAAU,CAAC,qBAAqB,EAAE,WAAW,CAAC,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;AAC9E,CAAC"} \ No newline at end of file diff --git a/components/daily-forecast.js b/components/daily-forecast.js new file mode 100644 index 0000000..826c57d --- /dev/null +++ b/components/daily-forecast.js @@ -0,0 +1,28 @@ +import { iconPath } from '../helpers/apiHelpers'; +import { printTempUnit, secondsToHHMM } from '../helpers/helpers'; +import * as openWeather from '../openWeatherIcons.json'; +import { formatInTimeZone } from 'date-fns-tz'; +export function renderDailyCards(forecast, unitState) { + // const map = JSON.parse(openWeather); + const map = openWeather; + const thisWeekHeading = document.createElement('h2'); + thisWeekHeading.textContent = 'This week'; + const daily = document.createElement('ul'); + daily.classList.add('daily-list'); + const template = document.querySelector('#daily-template'); + for (const day in forecast) { + const dailyCard = document.importNode(template.content, true); + const prop = forecast[day].weather; + const weatherIcon = new Image(); + weatherIcon.src = iconPath + `${map[prop].image}.svg`; + dailyCard.querySelector('.date').textContent = formatInTimeZone(forecast[day].timestamp * 1000, secondsToHHMM(forecast[day].timezone_offset), 'iiii, MMMM d'); + dailyCard.querySelector('.icon').appendChild(weatherIcon); + dailyCard.querySelector('.description').textContent = map[prop].label; + dailyCard.querySelector('.high').innerHTML = `${forecast[day].temp_high}${printTempUnit(unitState)}`; + dailyCard.querySelector('.low').innerHTML = `${forecast[day].temp_low}${printTempUnit(unitState)}`; + daily.appendChild(dailyCard); + } + document.querySelector('#daily-forecast')?.replaceChildren(daily); + document.querySelector('#daily-forecast')?.prepend(thisWeekHeading); +} +//# sourceMappingURL=daily-forecast.js.map \ No newline at end of file diff --git a/components/daily-forecast.js.map b/components/daily-forecast.js.map new file mode 100644 index 0000000..63a17a2 --- /dev/null +++ b/components/daily-forecast.js.map @@ -0,0 +1 @@ +{"version":3,"file":"daily-forecast.js","sourceRoot":"","sources":["../../src/components/daily-forecast.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,KAAK,WAAW,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,MAAM,UAAU,gBAAgB,CAAC,QAAsB,EAAE,SAAgB;IACvE,uCAAuC;I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,EAAE,CAAC;QAC9B,SAAS,CAAC,aAAa,CAAC,MAAM,CAAE,CAAC,SAAS,GAAG,GAC3C,QAAQ,CAAC,GAAG,CAAC,CAAC,QAChB,GAAG,aAAa,CAAC,SAAS,CAAC,EAAE,CAAC;QAE9B,KAAK,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;IAC/B,CAAC;IAED,QAAQ,CAAC,aAAa,CAAC,iBAAiB,CAAC,EAAE,eAAe,CAAC,KAAK,CAAC,CAAC;IAClE,QAAQ,CAAC,aAAa,CAAC,iBAAiB,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;AACtE,CAAC"} \ No newline at end of file diff --git a/components/dataCharts.js b/components/dataCharts.js new file mode 100644 index 0000000..cf140e9 --- /dev/null +++ b/components/dataCharts.js @@ -0,0 +1,215 @@ +import Chart from 'chart.js/auto'; +import 'chartjs-adapter-date-fns'; +import ChartDataLabels from 'chartjs-plugin-datalabels'; +import { enUS } from 'date-fns/locale'; +import { Units } from '../types/appTypes.types'; +//chart 1 ===================> +let chart1, chart2; +export async function renderChart(forecast, unitState) { + const getMaxValueWithPadding = () => { + return (Math.max(...forecast.map((row) => (row.rain ?? 0) + (row.snow ?? 0))) * + 1.1); + }; + Chart.defaults.color = 'rgba(255, 255, 255, 0.8)'; + const chartCtr = document.querySelector('#temp-chart1'); + if (chart1) + chart1.destroy(); + if (chart2) + chart2.destroy(); + chart1 = new Chart(chartCtr, { + type: 'line', + plugins: [ChartDataLabels], + options: { + layout: { + padding: { + bottom: 47.15, + }, + }, + maintainAspectRatio: false, + animation: false, + plugins: { + legend: { + display: false, + }, + }, + scales: { + x: { + adapters: { + date: { + locale: enUS, + }, + }, + grid: { + display: false, + }, + type: 'time', + ticks: { + stepSize: 3, + major: { + enabled: true, + }, + }, + time: { + unit: 'hour', + tooltipFormat: 'HH:mm', + }, + position: 'top', + }, + yTemp: { + ticks: { + display: false, + }, + grid: { + display: false, + }, + border: { + display: false, + }, + suggestedMin: 0, + }, + yPop: { + display: false, + // falsy OR in case get MaxValue returns 0 due to dataset of only 0s + max: getMaxValueWithPadding() || 1, + }, + yLev: { + display: false, + }, + }, + }, + data: { + labels: forecast.map((row) => row.date), + datasets: [ + { + type: 'line', + label: 'Temperature', + data: forecast.map((row) => row.temp), + tension: 0.4, + pointStyle: 'rectRounded', + yAxisID: 'yTemp', + datalabels: { + display: false, + }, + backgroundColor: 'rgba(255, 255, 255, 0.9)', + borderColor: 'rgba(255, 255, 255, 0.4)', + }, + { + label: 'Amount of precipitation in the last 3 hours', + type: 'bar', + data: forecast.map((row) => { + return (row.rain ?? 0) + (row.snow ?? 0); + }), + yAxisID: 'yPop', + backgroundColor: 'rgba(151,187,205,0.5)', + borderColor: 'rgba(151,187,205,0.8)', + borderWidth: 1.5, + borderRadius: 4, + datalabels: { + labels: { + description: { + anchor: 'start', + align: 'start', + font: { + size: 8.5, + }, + formatter: (value, context) => { + const bar = forecast[context.dataIndex]; + const words = bar.weather.description.split(' '); + return [...words]; + }, + }, + precipitation: { + anchor: 'end', + align: 'end', + offset: 15, + font: { + size: 8.3, + weight: 'bold', + }, + formatter: (value, context) => { + if (value) + return `${value} mm/h`; + else + return ''; + }, + textAlign: 'center', + }, + probability: { + anchor: 'end', + align: 'end', + font: { + size: 8.3, + }, + formatter: (value, context) => { + const bar = forecast[context.dataIndex]; + return `${(bar.pop * 100).toFixed()}%`; + }, + textAlign: 'center', + }, + }, + }, + }, + ], + }, + }); + // Chart2 ===================> + const chartCtr2 = document.querySelector('#temp-chart2'); + chart2 = new Chart(chartCtr2, { + type: 'line', + options: { + maintainAspectRatio: false, + layout: { + padding: { + top: 30, + bottom: 41, + }, + }, + animation: false, + plugins: { + legend: { + display: false, + }, + }, + scales: { + x: { + ticks: { + display: false, + }, + }, + y: { + afterFit: (ctx) => { + ctx.width = 43; + }, + ticks: { + callback: (value) => { + if (unitState == Units.metric) + return `${value}\u00B0C`; + else + return `${value}\u00B0F`; + }, + }, + suggestedMin: 0, + }, + }, + }, + data: { + labels: forecast.map((row) => row.date), + datasets: [ + { + label: 'temp every 3 hrs', + data: forecast.map((row) => row.temp), + }, + ], + }, + }); +} +function hexToRGB(hex, alpha) { + var r = parseInt(hex.slice(1, 3), 16), g = parseInt(hex.slice(3, 5), 16), b = parseInt(hex.slice(5, 7), 16); + if (alpha) { + return 'rgba(' + r + ', ' + g + ', ' + b + ', ' + alpha + ')'; + } + else { + return 'rgb(' + r + ', ' + g + ', ' + b + ')'; + } +} +//# sourceMappingURL=dataCharts.js.map \ No newline at end of file diff --git a/components/dataCharts.js.map b/components/dataCharts.js.map new file mode 100644 index 0000000..fb54e93 --- /dev/null +++ b/components/dataCharts.js.map @@ -0,0 +1 @@ +{"version":3,"file":"dataCharts.js","sourceRoot":"","sources":["../../src/components/dataCharts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,eAAe,CAAC;AAClC,OAAO,0BAA0B,CAAC;AAClC,OAAO,eAAe,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAe,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAE7D,8BAA8B;AAC9B,IAAI,MAAa,EAAE,MAAa,CAAC;AACjC,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,QAAuB,EAAE,SAAgB;IACzE,MAAM,sBAAsB,GAAG,GAAG,EAAE;QAClC,OAAO,CACL,IAAI,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC;YACrE,GAAG,CACJ,CAAC;IACJ,CAAC,CAAC;IAEF,KAAK,CAAC,QAAQ,CAAC,KAAK,GAAG,0BAA0B,CAAC;IAClD,MAAM,QAAQ,GAAG,QAAQ,CAAC,aAAa,CAAC,cAAc,CAAsB,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J,OAAO,MAAM,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,GAAG,GAAG,CAAC;IAChD,CAAC;AACH,CAAC"} \ No newline at end of file diff --git a/components/date-time.js b/components/date-time.js new file mode 100644 index 0000000..0c6f546 --- /dev/null +++ b/components/date-time.js @@ -0,0 +1,10 @@ +import { getElement } from '../utilities/typeUtility'; +import { formatInTimeZone } from 'date-fns-tz'; +export function renderQueryTitle(weatherObj) { + const dateTitle = getElement('#local-date', HTMLHeadingElement); + const timeTitle = getElement('#local-time', HTMLHeadingElement); + //set date and time seperately for styling purposes + dateTitle.textContent = formatInTimeZone(weatherObj.dt * 1000, weatherObj.timezone, 'do MMMM'); + timeTitle.textContent = formatInTimeZone(weatherObj.dt * 1000, weatherObj.timezone, 'h:mm aaaa O'); +} +//# sourceMappingURL=date-time.js.map \ No newline at end of file diff --git a/components/date-time.js.map b/components/date-time.js.map new file mode 100644 index 0000000..7272945 --- /dev/null +++ b/components/date-time.js.map @@ -0,0 +1 @@ +{"version":3,"file":"date-time.js","sourceRoot":"","sources":["../../src/components/date-time.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,MAAM,UAAU,gBAAgB,CAAC,UAAuB;IACtD,MAAM,SAAS,GAAuB,UAAU,CAC9C,aAAa,EACb,kBAAkB,CACnB,CAAC;IACF,MAAM,SAAS,GAAuB,UAAU,CAC9C,aAAa,EACb,kBAAkB,CACnB,CAAC;IAEF,mDAAmD;IACnD,SAAS,CAAC,WAAW,GAAG,gBAAgB,CACtC,UAAU,CAAC,EAAE,GAAG,IAAI,EACpB,UAAU,CAAC,QAAQ,EACnB,SAAS,CACV,CAAC;IAEF,SAAS,CAAC,WAAW,GAAG,gBAAgB,CACtC,UAAU,CAAC,EAAE,GAAG,IAAI,EACpB,UAAU,CAAC,QAAQ,EACnB,aAAa,CACd,CAAC;AACJ,CAAC"} \ No newline at end of file diff --git a/components/highlights.js b/components/highlights.js new file mode 100644 index 0000000..6fb8065 --- /dev/null +++ b/components/highlights.js @@ -0,0 +1,29 @@ +import { Units } from '../types/appTypes.types'; +import { convertToBeaufort, mpsToKmh } from '../helpers/beaufort'; +import { printSpeedUnit } from '../helpers/helpers'; +import { getElement } from '../utilities/typeUtility'; +import { formatInTimeZone } from 'date-fns-tz'; +export function renderHighlights(current, unitState) { + const template = getElement('#daily-statistics', HTMLTemplateElement); + const highlights = document.createElement('ul'); + const highlightCard = document.importNode(template.content, true); + highlightCard.querySelector('#sunrise').textContent = formatInTimeZone(current.highlights.sunrise, current.timezone, 'hh:mm aaaa'); + highlightCard.querySelector('#sunset').textContent = formatInTimeZone(current.highlights.sunset, current.timezone, 'hh:mm aaaa'); + highlightCard.querySelector('#humidity').textContent = + `${current.highlights.humidity}%`; + highlightCard.querySelector('#pressure').textContent = + `${current.highlights.pressure}hPa`; + highlightCard.querySelector('#beaufort').src = + `./static/assets/weather-icons-master/production/line/all/wind-beaufort-${convertToBeaufort(current.highlights.wind_speed, unitState)}.svg`; + // ternary condition to check unit state, if metric convert mps to kmh and then print unit + highlightCard.querySelector('#windspeed').textContent = `${unitState === Units.metric + ? mpsToKmh(current.highlights.wind_speed).toFixed(2) + : current.highlights.wind_speed}${printSpeedUnit(unitState)} `; + highlightCard.querySelector('#precipitation').textContent = `${(current.highlights.rain ?? 0) + (current.highlights.snow ?? 0)}mm/h `; + highlightCard.querySelector('#pop').textContent = + `${current.highlights.pop}%`; + highlightCard.querySelector('#uv').textContent = `${current.highlights.uvi}`; + highlights.appendChild(highlightCard); + getElement('#highlights', HTMLElement).replaceChildren(highlights); +} +//# sourceMappingURL=highlights.js.map \ No newline at end of file diff --git a/components/highlights.js.map b/components/highlights.js.map new file mode 100644 index 0000000..324017a --- /dev/null +++ b/components/highlights.js.map @@ -0,0 +1 @@ +{"version":3,"file":"highlights.js","sourceRoot":"","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,EAC7B,SAAS,CACV,MAAM,CAAC;IAEV,0FAA0F;IAC1F,aAAa,CAAC,aAAa,CAAC,YAAY,CAAE,CAAC,WAAW,GAAG,GACvD,SAAS,KAAK,KAAK,CAAC,MAAM;QACxB,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;QACpD,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,UACzB,GAAG,cAAc,CAAC,SAAS,CAAC,GAAG,CAAC;IAEhC,aAAa,CAAC,aAAa,CAAC,gBAAgB,CAAE,CAAC,WAAW,GAAG,GAC3D,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,IAAI,CAAC,CAChE,OAAO,CAAC;IAER,aAAa,CAAC,aAAa,CAAC,MAAM,CAAE,CAAC,WAAW;QAC9C,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG,GAAG,CAAC;IAE/B,aAAa,CAAC,aAAa,CAAC,KAAK,CAAE,CAAC,WAAW,GAAG,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC;IAC9E,UAAU,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;IACtC,UAAU,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC;AACrE,CAAC"} \ No newline at end of file diff --git a/helpers/apiHelpers.js b/helpers/apiHelpers.js new file mode 100644 index 0000000..7cdafef --- /dev/null +++ b/helpers/apiHelpers.js @@ -0,0 +1,58 @@ +import { Units } from '../types/appTypes.types'; +import { fetchData } from '../utilities/apiUtilities'; +export async function fetchCities(query) { + const GEO_CITIES_KEY = 'fdd238edc7mshc7ce70a38dec71cp1f8681jsn7a6eaf6f76cd'; + const options = { + headers: { + 'X-RapidAPI-Key': GEO_CITIES_KEY, + 'X-RapidAPI-Host': 'wft-geo-db.p.rapidapi.com', + }, + }; + const cities = await fetchData({ + url: url.geoCities(query), + options: options, + }); + //debating whether to abstract away the below mapping step and just return api response + return cities.data.map((city) => { + return { + label: { + name: city.name, + region: city.region, + country: city.country, + countryCode: city.countryCode, + }, + coord: { + lat: city.latitude, + lon: city.longitude, + }, + }; + }); +} +export const iconPath = './static/assets/weather-icons-master/production/line/openweathermap/'; +export const WEATHER_API_URL = 'https://api.openweathermap.org/data/'; +export const GEO_CITIES_URL = 'https://wft-geo-db.p.rapidapi.com/v1/geo/cities/?sort=-population'; +export const url = { + weather(coord) { + if (!coord.lat || !coord.lon) { + throw new Error(); + } + return `${WEATHER_API_URL}3.0/onecall?lat=${coord.lat}&lon=${coord.lon}&appid=${process.env.API_KEY}`; + }, + forecast(coord) { + if (!coord.lat || !coord.lon) { + throw new Error(); + } + return `${WEATHER_API_URL}2.5/forecast?lat=${coord.lat}&lon=${coord.lon}&appid=${process.env.API_KEY}`; + }, + geo(city = '', country = '') { + return `https://api.openweathermap.org/geo/1.0/direct?q=${city},${country}&appid=${process.env.API_KEY}`; + }, + geoCities(city = '') { + return GEO_CITIES_URL + `&namePrefix=${city}&limit=7`; + }, + //return endpoint path for specified units + units(unit = Units.metric) { + return `&units=${unit}`; + }, +}; +//# sourceMappingURL=apiHelpers.js.map \ No newline at end of file diff --git a/helpers/apiHelpers.js.map b/helpers/apiHelpers.js.map new file mode 100644 index 0000000..9c80e2d --- /dev/null +++ b/helpers/apiHelpers.js.map @@ -0,0 +1 @@ +{"version":3,"file":"apiHelpers.js","sourceRoot":"","sources":["../../src/helpers/apiHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAExE,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAEtD,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,KAAa;IAC7C,MAAM,cAAc,GAAG,oDAAoD,CAAC;IAC5E,MAAM,OAAO,GAAG;QACd,OAAO,EAAE;YACP,gB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;QACpB,CAAC;QACD,OAAO,GAAG,eAAe,oBAAoB,KAAK,CAAC,GAAG,QAAQ,KAAK,CAAC,GAAG,UAAU,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;IACzG,CAAC;IACD,GAAG,CAAC,OAAe,EAAE,EAAE,UAAkB,EAAE;QACzC,OAAO,mDAAmD,IAAI,IAAI,OAAO,UAAU,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;IAC3G,CAAC;IAED,SAAS,CAAC,OAAe,EAAE;QACzB,OAAO,cAAc,GAAG,eAAe,IAAI,UAAU,CAAC;IACxD,CAAC;IAED,0CAA0C;IAC1C,KAAK,CAAC,OAAc,KAAK,CAAC,MAAM;QAC9B,OAAO,UAAU,IAAI,EAAE,CAAC;IAC1B,CAAC;CACF,CAAC"} \ No newline at end of file diff --git a/helpers/beaufort.js b/helpers/beaufort.js new file mode 100644 index 0000000..bb9653c --- /dev/null +++ b/helpers/beaufort.js @@ -0,0 +1,29 @@ +import { Units } from '../types/appTypes.types'; +const kmhBoundaries = [ + 2, 6, 12, 20, 29, 39, 50, 62, 75, 89, 103, 118, 133, 149, 166, 184, 201, +]; +const mphBoundaries = [ + 1, 4, 8, 13, 19, 25, 32, 39, 47, 55, 64, 73, 83, 93, 104, 115, 125, +]; +export function convertToBeaufort(speed, unitState) { + if (speed < 0) { + throw new Error('Invalid speed value'); + } + let beaufort; + if (unitState == Units.metric) { + speed = mpsToKmh(speed); + beaufort = kmhBoundaries.reduce((acc, curr) => { + return acc + (speed >= curr ? 1 : 0); + }, 0); + } + else { + beaufort = mphBoundaries.reduce((acc, curr) => { + return acc + (speed > curr ? 1 : 0); + }, 0); + } + return beaufort; +} +export function mpsToKmh(speed) { + return 3.6 * speed; +} +//# sourceMappingURL=beaufort.js.map \ No newline at end of file diff --git a/helpers/beaufort.js.map b/helpers/beaufort.js.map new file mode 100644 index 0000000..36478d2 --- /dev/null +++ b/helpers/beaufort.js.map @@ -0,0 +1 @@ +{"version":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,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACtC,CAAC,EAAE,CAAC,CAAC,CAAC;IACR,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,KAAa;IACpC,OAAO,GAAG,GAAG,KAAK,CAAC;AACrB,CAAC"} \ No newline at end of file diff --git a/helpers/dataHelpers.js b/helpers/dataHelpers.js new file mode 100644 index 0000000..8484713 --- /dev/null +++ b/helpers/dataHelpers.js @@ -0,0 +1,101 @@ +import { groupBy, trimDate, getObjectKeys, getMostFrequent, } from '../utilities/dataUtils'; +// /* +// -dynamic function generator: returns a function that groups data based on the property (key) called in initial argument. +// -meant to be stored in a variable that will call this new function and take in arrays +// */ +// export function groupBy(key: keyof ForecastData & keyof DescriptionData) { +// /* +// returned dynamic function that accepts arrays as argument +// */ +// return function group(arr: Items) { +// return arr.reduce((acc, currObj) => { +// // create variable storing the value of the key of interest +// const prop = currObj[key]; +// // destructure the rest of values into an array, extracting the date out since we don't need it anymore +// // date should be key no? but typescript isnt making it easy +// /*const { date, ...rest } = currObj;*/ +// //we check if it already contains an entry for that grouping criteria or start an empty array literal for it +// acc[prop] = acc[prop] ||= []; +// //finall we push into thisewly creared/existing property's value all the remaining properties stored inside the rest variable +// acc[prop]?.push(currObj); +// return acc; +// }, {}); +// }; +// } +export function createForecastArr(response) { + const obj = []; + response?.list.forEach((item) => { + let forecast = { + dt: item.dt, + date: item.dt_txt, + pop: item.pop, + temp: item.main.temp, + weather: item.weather[0], + timezone_offset: response.city.timezone, + }; + if (item.rain) + forecast.rain = item.rain['3h']; + if (item.snow) + forecast.snow = item.snow['3h']; + obj.push(forecast); + }); + return obj; +} // parameter for forecast response object because the OneCallResponse does not carry the location name +export function parseCurrentWeather(response, foreResponse) { + return { + name: foreResponse.city.name, + weather_id: response.current.weather[0].id, + weather_condition: response.current.weather[0].description, + weather_main: response.current.weather[0].main, + weather_icon: response.current.weather[0].icon, + dt: response.current.dt, + temp: (Math.round(response.current.temp * 2) / 2).toFixed(), + feels_like: (Math.round(response.current.feels_like * 2) / 2).toFixed(), + timezone: response.timezone, + country: foreResponse.city.country, + highlights: { + sunrise: response.current.sunrise, + sunset: response.current.sunset, + uvi: response.current.uvi, + humidity: response.current.humidity, + pressure: response.current.pressure, + wind_speed: response.current.wind_speed, + wind_deg: response.current.wind_deg, + pop: response.hourly[0].pop, + rain: response.current.rain?.['1h'] ?? 0, + snow: response.current.snow?.['1h'] ?? 0, + visibility: 0, + }, + }; +} +export function getCoord(response) { + return { + lat: response[0].lat, + lon: response[0].lon, + }; +} +export function getHigh(arr) { + return arr.reduce((a, b) => (a < b.temp ? b.temp : a), arr[0].temp); +} +export function getLow(arr) { + return arr.reduce((a, b) => (a < b.temp ? a : b.temp), arr[0].temp); +} +export function parse5DayForecast(arr) { + const groupByDate = groupBy('date'); + const trimmed = trimDate(arr); + const sorted = groupByDate(trimmed); + const keys = getObjectKeys(sorted); + const forecastWeather = {}; + for (const key of keys) { + // let dailyDescriptions = litty[key].map((item) => item.weather.description); + forecastWeather[key] = { + temp_high: Math.round(getHigh(sorted[key])).toFixed(1), + temp_low: Math.round(getLow(sorted[key])).toFixed(1), + weather: getMostFrequent(sorted[key]), + timestamp: sorted[key][0].dt, + timezone_offset: sorted[key][0].timezone_offset, + }; + } + return forecastWeather; +} +//# sourceMappingURL=dataHelpers.js.map \ No newline at end of file diff --git a/helpers/dataHelpers.js.map b/helpers/dataHelpers.js.map new file mode 100644 index 0000000..31ec6d8 --- /dev/null +++ b/helpers/dataHelpers.js.map @@ -0,0 +1 @@ +{"version":3,"file":"dataHelpers.js","sourceRoot":"","sources":["../../src/helpers/dataHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,QAAQ,EACR,aAAa,EACb,eAAe,GAChB,MAAM,wBAAwB,CAAC;AAchC,KAAK;AACL,2HAA2H;AAC3H,wFAAwF;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,CAAC,GAAG;YACrB,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;YACtD,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;YACpD,OAAO,EAAE,eAAe,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACrC,SAAS,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE;YAC5B,eAAe,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,eAAe;SAChD,CAAC;IACJ,CAAC;IACD,OAAO,eAAe,CAAC;AACzB,CAAC"} \ No newline at end of file diff --git a/helpers/helpers.js b/helpers/helpers.js new file mode 100644 index 0000000..f3b6264 --- /dev/null +++ b/helpers/helpers.js @@ -0,0 +1,50 @@ +import { getElement } from '../utilities/typeUtility'; +import { Units } from '../types/appTypes.types'; +export function printTempUnit(unitState) { + if (unitState == Units.metric) + return '°C'; + else + return '°F'; +} +export function printSpeedUnit(unitState) { + if (unitState == Units.metric) + return 'km/h'; + else + return 'mph'; +} +export function parseUnitState(flag) { + if (!flag) + return Units.metric; + else + return Units.imperial; +} +export function secondsToHHMM(seconds) { + if ((seconds >= 3600 || seconds <= -3600) && + (seconds >= -90000 || seconds <= 90000)) { + if (seconds > 0) { + return '+' + new Date(seconds * 1000).toISOString().substring(11, 16); + } + else { + return '-' + new Date(seconds * 1000).toISOString().substring(11, 16); + } + } + else { + throw Error('Number has to be more than 3600 and less than 90000 to maintain HH:MM format'); + } +} +export function updateDateTime() { + const now = new Date(); + const currentDate = now.toLocaleString('en-CA', { + day: 'numeric', + month: 'short', + year: 'numeric', + }); + const currentTime = now.toLocaleTimeString('en-US', { + weekday: 'long', + hour: 'numeric', + minute: '2-digit', + }); + getElement('#user-date', HTMLHeadingElement).textContent = + currentDate + ' - ' + currentTime; +} +//# sourceMappingURL=helpers.js.map \ No newline at end of file diff --git a/helpers/helpers.js.map b/helpers/helpers.js.map new file mode 100644 index 0000000..cea231e --- /dev/null +++ b/helpers/helpers.js.map @@ -0,0 +1 @@ +{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/helpers/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAEhD,MAAM,UAAU,aAAa,CAAC,SAAgB;IAC5C,IAAI,SAAS,IAAI,KAAK,CAAC,MAAM;QAAE,OAAO,QAAQ,CAAC;;QAC1C,OAAO,QAAQ,CAAC;AACvB,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,SAAgB;IAC7C,IAAI,SAAS,IAAI,KAAK,CAAC,MAAM;QAAE,OAAO,MAAM,CAAC;;QACxC,OAAO,KAAK,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,IAAa;IAC1C,IAAI,CAAC,IAAI;QAAE,OAAO,KAAK,CAAC,MAAM,CAAC;;QAC1B,OAAO,KAAK,CAAC,QAAQ,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,OAAe;IAC3C,IACE,CAAC,OAAO,IAAI,IAAI,IAAI,OAAO,IAAI,CAAC,IAAI,CAAC;QACrC,CAAC,OAAO,IAAI,CAAC,KAAK,IAAI,OAAO,IAAI,KAAK,CAAC,EACvC,CAAC;QACD,IAAI,OAAO,GAAG,CAAC,EAAE,CAAC;YAChB,OAAO,GAAG,GAAG,IAAI,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QACxE,CAAC;aACI,CAAC;YACJ,OAAO,GAAG,GAAG,IAAI,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QACxE,CAAC;IACH,CAAC;SACI,CAAC;QACJ,MAAM,KAAK,CACT,8EAA8E,CAC/E,CAAC;IACJ,CAAC;AACH,CAAC;AACD,MAAM,UAAU,cAAc;IAC5B,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;IACvB,MAAM,WAAW,GAAG,GAAG,CAAC,cAAc,CAAC,OAAO,EAAE;QAC9C,GAAG,EAAE,SAAS;QACd,KAAK,EAAE,OAAO;QACd,IAAI,EAAE,SAAS;KAChB,CAAC,CAAC;IAEH,MAAM,WAAW,GAAG,GAAG,CAAC,kBAAkB,CAAC,OAAO,EAAE;QAClD,OAAO,EAAE,MAAM;QACf,IAAI,EAAE,SAAS;QACf,MAAM,EAAE,SAAS;KAClB,CAAC,CAAC;IAEH,UAAU,CAAC,YAAY,EAAE,kBAAkB,CAAC,CAAC,WAAW;QACtD,WAAW,GAAG,KAAK,GAAG,WAAW,CAAC;AACtC,CAAC"} \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..1a8c86b --- /dev/null +++ b/index.js @@ -0,0 +1,10 @@ +import { autoSearch } from './components/autocomplete'; +import '@algolia/autocomplete-theme-classic'; +import { updateDateTime } from './helpers/helpers'; +import './style.css'; +setInterval(updateDateTime, 1000); +autoSearch(); +if (module && module.hot) { + module.hot.accept(); +} +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..c1172e3 --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,qCAAqC,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,aAAa,CAAC;AACrB,WAAW,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;AAElC,UAAU,EAAE,CAAC;AAEb,IAAI,MAAM,IAAI,MAAM,CAAC,GAAG,EAAE,CAAC;IACzB,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;AACtB,CAAC"} \ No newline at end of file diff --git a/openWeatherIcons.json b/openWeatherIcons.json new file mode 100644 index 0000000..91ea69a --- /dev/null +++ b/openWeatherIcons.json @@ -0,0 +1,272 @@ +{ + "200": { + "label": "thunderstorm with light rain", + "icon": "storm-showers", + "image": "11d" + }, + "201": { + "label": "thunderstorm with rain", + "icon": "storm-showers", + "image": "11d" + }, + "202": { + "label": "thunderstorm with heavy rain", + "icon": "storm-showers", + "image": "11d" + }, + "210": { + "label": "light thunderstorm", + "icon": "storm-showers", + "image": "11d" + }, + "211": { + "label": "thunderstorm", + "icon": "thunderstorm", + "image": "11d" + }, + "212": { + "label": "heavy thunderstorm", + "icon": "thunderstorm", + "image": "11d" + }, + "221": { + "label": "ragged thunderstorm", + "icon": "thunderstorm", + "image": "11d" + }, + "230": { + "label": "thunderstorm with light drizzle", + "icon": "storm-showers", + "image": "11d" + }, + "231": { + "label": "thunderstorm with drizzle", + "icon": "storm-showers", + "image": "11d" + }, + "232": { + "label": "thunderstorm with heavy drizzle", + "icon": "storm-showers", + "image": "11d" + }, + "300": { + "label": "light intensity drizzle", + "icon": "sprinkle", + "image": "09d" + }, + "301": { + "label": "drizzle", + "icon": "sprinkle", + "image": "09d" + }, + "302": { + "label": "heavy intensity drizzle", + "icon": "sprinkle", + "image": "09d" + }, + "310": { + "label": "light intensity drizzle rain", + "icon": "sprinkle", + "image": "09d" + }, + "311": { + "label": "drizzle rain", + "icon": "sprinkle", + "image": "09d" + }, + "312": { + "label": "heavy intensity drizzle rain", + "icon": "sprinkle", + "image": "09d" + }, + "313": { + "label": "shower rain and drizzle", + "icon": "sprinkle", + "image": "09d" + }, + "314": { + "label": "heavy shower rain and drizzle", + "icon": "sprinkle", + "image": "09d" + }, + "321": { + "label": "shower drizzle", + "icon": "sprinkle", + "image": "09d" + }, + "500": { + "label": "light rain", + "icon": "rain", + "image": "10d" + }, + "501": { + "label": "moderate rain", + "icon": "rain", + "image": "10d" + }, + "502": { + "label": "heavy intensity rain", + "icon": "rain", + "image": "10d" + }, + "503": { + "label": "very heavy rain", + "icon": "rain", + "image": "10d" + }, + "504": { + "label": "extreme rain", + "icon": "rain", + "image": "10d" + }, + "511": { + "label": "freezing rain", + "icon": "rain-mix", + "image": "10d" + }, + "520": { + "label": "light intensity shower rain", + "icon": "showers", + "image": "10d" + }, + "521": { + "label": "shower rain", + "icon": "showers", + "image": "10d" + }, + "522": { + "label": "heavy intensity shower rain", + "icon": "showers", + "image": "10d" + }, + "531": { + "label": "ragged shower rain", + "icon": "showers", + "image": "10d" + }, + "600": { + "label": "light snow", + "icon": "snow", + "image": "13d" + }, + "601": { + "label": "snow", + "icon": "snow", + "image": "13d" + }, + "602": { + "label": "heavy snow", + "icon": "snow", + "image": "13d" + }, + "611": { + "label": "sleet", + "icon": "sleet", + "image": "13d" + }, + "612": { + "label": "shower sleet", + "icon": "sleet", + "image": "13d" + }, + "615": { + "label": "light rain and snow", + "icon": "rain-mix", + "image": "13d" + }, + "616": { + "label": "rain and snow", + "icon": "rain-mix", + "image": "13d" + }, + "620": { + "label": "light shower snow", + "icon": "rain-mix", + "image": "13d" + }, + "621": { + "label": "shower snow", + "icon": "rain-mix", + "image": "13d" + }, + "622": { + "label": "heavy shower snow", + "icon": "rain-mix", + "image": "13d" + }, + "701": { + "label": "mist", + "icon": "sprinkle", + "image": "50d" + }, + "711": { + "label": "smoke", + "icon": "smoke", + "image": "50d" + }, + "721": { + "label": "haze", + "icon": "day-haze", + "image": "50d" + }, + "731": { + "label": "sand, dust whirls", + "icon": "cloudy-gusts", + "image": "50d" + }, + "741": { + "label": "fog", + "icon": "fog", + "image": "50d" + }, + "751": { + "label": "sand", + "icon": "cloudy-gusts", + "image": "50d" + }, + "761": { + "label": "dust", + "icon": "dust", + "image": "50d" + }, + "762": { + "label": "volcanic ash", + "icon": "smog", + "image": "50d" + }, + "771": { + "label": "squalls", + "icon": "day-windy", + "image": "50d" + }, + "781": { + "label": "tornado", + "icon": "tornado", + "image": "50d" + }, + "800": { + "label": "clear sky", + "icon": "sunny", + "image": "01d" + }, + "801": { + "label": "few clouds", + "icon": "cloudy", + "image": "02d" + }, + "802": { + "label": "scattered clouds", + "icon": "cloudy", + "image": "03d" + }, + "803": { + "label": "broken clouds", + "icon": "cloudy", + "image": "04d" + }, + "804": { + "label": "overcast clouds", + "icon": "cloudy", + "image": "04d" + } +} diff --git a/types/appTypes.types.js b/types/appTypes.types.js new file mode 100644 index 0000000..30b0973 --- /dev/null +++ b/types/appTypes.types.js @@ -0,0 +1,25 @@ +export var Units; +(function (Units) { + Units["metric"] = "metric"; + Units["imperial"] = "imperial"; +})(Units || (Units = {})); +export var compassSector; +(function (compassSector) { + compassSector[compassSector["N"] = 0] = "N"; + compassSector[compassSector["NNE"] = 1] = "NNE"; + compassSector[compassSector["NE"] = 2] = "NE"; + compassSector[compassSector["ENE"] = 3] = "ENE"; + compassSector[compassSector["E"] = 4] = "E"; + compassSector[compassSector["ESE"] = 5] = "ESE"; + compassSector[compassSector["SE"] = 6] = "SE"; + compassSector[compassSector["SSE"] = 7] = "SSE"; + compassSector[compassSector["S"] = 8] = "S"; + compassSector[compassSector["SSW"] = 9] = "SSW"; + compassSector[compassSector["SW"] = 10] = "SW"; + compassSector[compassSector["WSW"] = 11] = "WSW"; + compassSector[compassSector["W"] = 12] = "W"; + compassSector[compassSector["WNW"] = 13] = "WNW"; + compassSector[compassSector["NW"] = 14] = "NW"; + compassSector[compassSector["NNW"] = 15] = "NNW"; +})(compassSector || (compassSector = {})); +//# sourceMappingURL=appTypes.types.js.map \ No newline at end of file diff --git a/types/appTypes.types.js.map b/types/appTypes.types.js.map new file mode 100644 index 0000000..1dad9cb --- /dev/null +++ b/types/appTypes.types.js.map @@ -0,0 +1 @@ +{"version":3,"file":"appTypes.types.js","sourceRoot":"","sources":["../../src/types/appTypes.types.ts"],"names":[],"mappings":"AAmEA,MAAM,CAAN,IAAY,KAGX;AAHD,WAAY,KAAK;IACf,0BAAiB,CAAA;IACjB,8BAAqB,CAAA;AACvB,CAAC,EAHW,KAAK,KAAL,KAAK,QAGhB;AAED,MAAM,CAAN,IAAY,aAiBX;AAjBD,WAAY,aAAa;IACvB,2CAAC,CAAA;IACD,+CAAG,CAAA;IACH,6CAAE,CAAA;IACF,+CAAG,CAAA;IACH,2CAAC,CAAA;IACD,+CAAG,CAAA;IACH,6CAAE,CAAA;IACF,+CAAG,CAAA;IACH,2CAAC,CAAA;IACD,+CAAG,CAAA;IACH,8CAAE,CAAA;IACF,gDAAG,CAAA;IACH,4CAAC,CAAA;IACD,gDAAG,CAAA;IACH,8CAAE,CAAA;IACF,gDAAG,CAAA;AACL,CAAC,EAjBW,aAAa,KAAb,aAAa,QAiBxB"} \ No newline at end of file diff --git a/types/geoDB.types.js b/types/geoDB.types.js new file mode 100644 index 0000000..30976d9 --- /dev/null +++ b/types/geoDB.types.js @@ -0,0 +1,3 @@ +// Generated by https://quicktype.io +export {}; +//# sourceMappingURL=geoDB.types.js.map \ No newline at end of file diff --git a/types/geoDB.types.js.map b/types/geoDB.types.js.map new file mode 100644 index 0000000..50c84db --- /dev/null +++ b/types/geoDB.types.js.map @@ -0,0 +1 @@ +{"version":3,"file":"geoDB.types.js","sourceRoot":"","sources":["../../src/types/geoDB.types.ts"],"names":[],"mappings":"AAAA,oCAAoC"} \ No newline at end of file diff --git a/types/openWeather.types.js b/types/openWeather.types.js new file mode 100644 index 0000000..b50e690 --- /dev/null +++ b/types/openWeather.types.js @@ -0,0 +1,3 @@ +// OpenWeather API Forecast Endpoint +export {}; +//# sourceMappingURL=openWeather.types.js.map \ No newline at end of file diff --git a/types/openWeather.types.js.map b/types/openWeather.types.js.map new file mode 100644 index 0000000..da06120 --- /dev/null +++ b/types/openWeather.types.js.map @@ -0,0 +1 @@ +{"version":3,"file":"openWeather.types.js","sourceRoot":"","sources":["../../src/types/openWeather.types.ts"],"names":[],"mappings":"AAAA,oCAAoC"} \ No newline at end of file diff --git a/utilities/apiUtilities.js b/utilities/apiUtilities.js new file mode 100644 index 0000000..dd8b873 --- /dev/null +++ b/utilities/apiUtilities.js @@ -0,0 +1,23 @@ +/* +-basic async function to hit api and return data of interest +-use url object methods to manipulate the sort of data returned +*/ +export async function fetchData({ url, units, options, }) { + const response = await fetch(url + (units ?? ''), options); + if (!response.ok) { + throw new HTTPError(response.status, response.statusText, response); + } + return await response.json(); +} +export class HTTPError extends Error { + response; + status; + statusText; + constructor(status, statusText, response) { + super(statusText); + this.status = status; + this.statusText = statusText; + this.response = response; + } +} +//# sourceMappingURL=apiUtilities.js.map \ No newline at end of file diff --git a/utilities/apiUtilities.js.map b/utilities/apiUtilities.js.map new file mode 100644 index 0000000..8c29242 --- /dev/null +++ b/utilities/apiUtilities.js.map @@ -0,0 +1 @@ +{"version":3,"file":"apiUtilities.js","sourceRoot":"","sources":["../../src/utilities/apiUtilities.ts"],"names":[],"mappings":"AAAA;;;EAGE;AACF,MAAM,CAAC,KAAK,UAAU,SAAS,CAAQ,EACrC,GAAG,EACH,KAAK,EACL,OAAO,GAKR;IACC,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC;IAE3D,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,IAAI,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;IACtE,CAAC;IACD,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;AAC/B,CAAC;AACD,MAAM,OAAO,SAAU,SAAQ,KAAK;IACzB,QAAQ,CAAM;IACd,MAAM,CAAS;IACf,UAAU,CAAS;IAE5B,YAAY,MAAc,EAAE,UAAkB,EAAE,QAAa;QAC3D,KAAK,CAAC,UAAU,CAAC,CAAC;QAClB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF"} \ No newline at end of file diff --git a/utilities/dataUtils.js b/utilities/dataUtils.js new file mode 100644 index 0000000..f5bf324 --- /dev/null +++ b/utilities/dataUtils.js @@ -0,0 +1,52 @@ +//trim Date/time string to date. (YYYY-MM-dd hh:mm:ss) => YYYY-MM-dd +export function trimDate(data) { + const forecast = []; + data.map((item) => { + // objects are passed by reference so clone object to prevent mutation of original + item = JSON.parse(JSON.stringify(item)); + item.date = item.date.substring(0, 10); + forecast.push(item); + }); + return forecast; +} +// K is the key that we're going to group by (e.g. date) +export function groupBy(key) { + // T is the full object data, must have the specified key (with a string value) + return function group(arr) { + // The result type is an object with string keys, an./d the value is an array of "T" items... but with K removed. + return arr.reduce((acc, currObj) => { + const { [key]: prop, ...rest } = currObj; + const group = (acc[prop] ||= []); + group.push(rest); + return acc; + }, {}); + }; +} +//DONE +export function getObjectKeys(object) { + return Object.keys(object); +} +export function getAverage(arr, isRound = true) { + let average = 0; + if (isRound) { + average = Math.round(arr.reduce((a, b) => a + b, 0) / arr.length); + } + else + average = +(arr.reduce((a, b) => a + b, 0) / arr.length).toFixed(2); + return average; +} +/* +- counts id property because that appears to be the primary key for weather conditions +- the other two weather properties can be extracted from json data map +*/ +export function getMostFrequent(obj) { + //create hash of amount of times each id value appears in array of date + const hashmap = obj.reduce((acc, val) => { + let valWeather = val.weather.id; + acc[valWeather] = (acc[valWeather] || 0) + 1; + return acc; + }, {}); + // return hash value with highest number + return Object.keys(hashmap).reduce((a, b) => hashmap[a] > hashmap[b] ? a : b); +} +//# sourceMappingURL=dataUtils.js.map \ No newline at end of file diff --git a/utilities/dataUtils.js.map b/utilities/dataUtils.js.map new file mode 100644 index 0000000..376a6bd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,OAAO,GAAG,IAAI;IACtD,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC;IACpE,CAAC;;QACI,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAEzE,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;EAGE;AACF,MAAM,UAAU,eAAe,CAC7B,GAAQ;IAER,uEAAuE;IACvE,MAAM,OAAO,GAAG,GAAG,CAAC,MAAM,CACxB,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QACX,IAAI,UAAU,GAAG,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;QAEhC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;QAC7C,OAAO,GAAG,CAAC;IACb,CAAC,EACD,EAA8B,CAC/B,CAAC;IAEF,wCAAwC;IACxC,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAC1C,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAChC,CAAC;AACJ,CAAC"} \ No newline at end of file diff --git a/utilities/typeUtility.js b/utilities/typeUtility.js new file mode 100644 index 0000000..f7ef3c3 --- /dev/null +++ b/utilities/typeUtility.js @@ -0,0 +1,8 @@ +export function getElement(selector, type) { + const el = document.querySelector(selector); + if (!(el instanceof type)) { + throw new Error('Element does not exist'); + } + return el; +} +//# sourceMappingURL=typeUtility.js.map \ No newline at end of file diff --git a/utilities/typeUtility.js.map b/utilities/typeUtility.js.map new file mode 100644 index 0000000..cc27dae --- /dev/null +++ b/utilities/typeUtility.js.map @@ -0,0 +1 @@ +{"version":3,"file":"typeUtility.js","sourceRoot":"","sources":["../../src/utilities/typeUtility.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,UAAU,CAExB,QAAgB,EAAE,IAAkB;IACpC,MAAM,EAAE,GAAG,QAAQ,CAAC,aAAa,CAA6B,QAAQ,CAAC,CAAC;IAExE,IAAI,CAAC,CAAC,EAAE,YAAY,IAAI,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC5C,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC"} \ No newline at end of file