@vixoniccom/aqi 0.0.2-dev.0 → 0.0.2-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build.zip CHANGED
Binary file
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "author": {
9
9
  "name": "Daniel Alvayay"
10
10
  },
11
- "version": "0.0.2-dev.0",
11
+ "version": "0.0.2-dev.1",
12
12
  "scripts": {
13
13
  "prepublishOnly": "vixonic-module-packager --mode=build",
14
14
  "watch": "vixonic-module-packager --mode=watch",
package/src/App.tsx CHANGED
@@ -15,6 +15,7 @@ export const App: React.FunctionComponent<Props> = ({ data, start }) => {
15
15
  const backgroundImageState = parameters.backgroundImage ? `url('${downloadsPath}/${parameters.backgroundImage.filename}')` : ''
16
16
  const [formattedData, setFormattedData] = useState<AqiData>()
17
17
  const cityInput = parameters?.cityInput || "santiago"
18
+ const msj0 = parameters?.msj0 || 'No hay datos para mostrar'
18
19
  const updateTime = 600000
19
20
 
20
21
  useEffect(() => {
@@ -22,10 +23,10 @@ export const App: React.FunctionComponent<Props> = ({ data, start }) => {
22
23
 
23
24
  const fetchData = async () => {
24
25
  try {
25
- const data = await getData(cityInput, updateTime)
26
+ const data = await getData(cityInput, updateTime, msj0)
26
27
  setFormattedData(data)
27
28
  } catch (error) {
28
- console.error('Error al obtener datos:', error)
29
+ console.error('Error fetching data:', error)
29
30
  setFormattedData(undefined)
30
31
  }
31
32
  }
@@ -77,7 +78,7 @@ export const App: React.FunctionComponent<Props> = ({ data, start }) => {
77
78
  }}>
78
79
  <FontLoader paths={['formatMjs.font']} parameters={parameters} downloadsPath={downloadsPath} />
79
80
  <div style={{ display: 'flex', position: 'relative', flex: '1 1 0%', flexDirection: 'column' }}>
80
- <FormattedText text={parameters?.msj0 || 'No hay datos para mostrar'} format={parameters?.formatMjs} />
81
+ <FormattedText text={msj0} format={parameters?.formatMjs} />
81
82
  </div>
82
83
  </div>
83
84
  )}
@@ -15,7 +15,7 @@ interface Props {
15
15
  format?: any
16
16
  lineHeight?: number
17
17
  maxChar?: number
18
- style?: number
18
+ style?: React.CSSProperties
19
19
  text: string
20
20
  unit?: string
21
21
  paddingBottom?: string
@@ -25,15 +25,14 @@ interface Props {
25
25
  export const FormattedText: React.FunctionComponent<Props> = ({ text, format, maxChar, lineHeight, style, unit, paddingBottom, paddingTop }) => {
26
26
  const trimText = (text: string, maxChar?: number) => {
27
27
  const isValid = maxChar && maxChar >= 3
28
- if (isValid && (text && text.length > maxChar)) {
28
+ if (isValid && text.length > maxChar) {
29
29
  const returnText = text.substring(0, maxChar - 3)
30
- returnText.substr(-1, 3)
31
30
  return `${returnText.trim()}...`
32
31
  }
33
32
  return text
34
33
  }
35
34
 
36
- const checkNested = (obj: any, path: any): any => {
35
+ const checkNested = (obj: any, path: string): any => {
37
36
  const arr = path.split('.')
38
37
  if (arr.length > 0) {
39
38
  if (obj.hasOwnProperty(arr[0])) {
@@ -51,10 +50,11 @@ export const FormattedText: React.FunctionComponent<Props> = ({ text, format, ma
51
50
  }
52
51
 
53
52
  const renderText = maxChar ? trimText(text, maxChar) : text
54
- let containerStyle = Object.assign({
53
+ let containerStyle = {
55
54
  display: 'inline-flex',
56
- justifyContent: getHorizontalAlignment(format.alignment)
57
- }, style)
55
+ justifyContent: getHorizontalAlignment(format.alignment),
56
+ ...style
57
+ }
58
58
 
59
59
  return (
60
60
  <div style={containerStyle}>
@@ -3,7 +3,8 @@ import localforage from 'localforage'
3
3
  import { AirQuality, AqiData, StorageData } from '../types'
4
4
  import { API_RESPONSE_STATUS } from '../utils'
5
5
 
6
- const TOKEN = process.env.AQI_TOKEN ?? ''
6
+ if (!process.env.AQI_TOKEN) console.warn('Env variable not found. Skipping API call.')
7
+ const TOKEN = process.env.AQI_TOKEN
7
8
 
8
9
  const refetchData = (referenceDate: Date, updateTime: number): boolean => {
9
10
  const now = new Date()
@@ -13,17 +14,13 @@ const refetchData = (referenceDate: Date, updateTime: number): boolean => {
13
14
  const sameDay = referenceDate.getDate() === now.getDate()
14
15
 
15
16
  if (sameYear && sameMonth && sameDay) {
16
- const differenceMinutes = Math.abs(now.getTime() - referenceDate.getTime())
17
- return differenceMinutes >= updateTime
17
+ const differenceMilliseconds = Math.abs(now.getTime() - referenceDate.getTime())
18
+ return differenceMilliseconds >= updateTime
18
19
  }
19
20
  return true
20
21
  }
21
22
 
22
23
  const requestData = async (cityInput: string): Promise<AirQuality | null> => {
23
- if (!TOKEN) {
24
- console.warn('VITE_AQI_TOKEN no está definido en el entorno. Se omitirá la llamada a la API.')
25
- return null
26
- }
27
24
  const URL = `https://api.waqi.info/feed/${cityInput}/?token=${TOKEN}`
28
25
  try {
29
26
  const response = await axios.get<AirQuality>(URL)
@@ -32,13 +29,13 @@ const requestData = async (cityInput: string): Promise<AirQuality | null> => {
32
29
  }
33
30
  return null
34
31
  } catch (error) {
35
- console.error('Error al obtener datos de AQI:', error)
32
+ console.error('Error fetching AQI data:', error)
36
33
  return null
37
34
  }
38
35
  }
39
36
 
40
- const processData = (response: AirQuality | null, cityInput: string): AqiData => {
41
- let data: AqiData = { city: cityInput, station: "Estación desconocida" }
37
+ const processData = (response: AirQuality | null, cityInput: string, defaultMsg: string): AqiData => {
38
+ let data: AqiData = { city: cityInput, station: defaultMsg }
42
39
  if (response?.status === API_RESPONSE_STATUS.OK) {
43
40
  data = {
44
41
  aqi: response.data.aqi,
@@ -49,12 +46,12 @@ const processData = (response: AirQuality | null, cityInput: string): AqiData =>
49
46
  return data
50
47
  }
51
48
 
52
- export const getData = async (cityInput: string, updateTime: number): Promise<AqiData> => {
49
+ export const getData = async (cityInput: string, updateTime: number, defaultMsg: string): Promise<AqiData> => {
53
50
  const storageData: StorageData | null = await localforage.getItem('aqi')
54
51
  let data
55
52
  if (!storageData?.item || storageData?.item.city !== cityInput || !storageData?.date || refetchData(new Date(storageData.date), updateTime)) {
56
53
  data = await requestData(cityInput)
57
- const processedData = processData(data, cityInput)
54
+ const processedData = processData(data, cityInput, defaultMsg)
58
55
  await localforage.setItem('aqi', { item: processedData, date: new Date() })
59
56
  return processedData
60
57
  } else {