All files / app/weather weatherPage.tsx

0% Statements 0/190
100% Branches 1/1
100% Functions 1/1
0% Lines 0/190

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214                                                                                                                                                                                                                                                                                                                                                                                                                                           
'use client';
 
import Link from 'next/link';
import {
  useCallback, useContext, useEffect, useState
} from 'react';
import Col from 'react-bootstrap/Col';
import Image from 'react-bootstrap/Image';
import Row from 'react-bootstrap/Row';
 
import styles from './weather.module.css';
 
import LoadingSpinner from '@/components/loadingSpinner/loadingSpinner';
import { WeatherResultJson } from '@/deprecated/common/weather';
import { AddAlertContext } from '@/utils/frontend/clientContexts';
 
export default function WeatherPage() {
  const addAlert = useContext(AddAlertContext);
  const [
    weatherData,
    setWeatherData,
  ] = useState<WeatherResultJson | null | undefined>();
  const [
    isLoading,
    setIsLoading,
  ] = useState(false);
  useEffect(() => {
    if (typeof weatherData !== 'undefined' || isLoading) {
      return;
    }
 
    setIsLoading(true);
    (async () => {
      try {
        const result: WeatherResultJson = await fetch('/weather.json')
          .then(r => r.json());
 
        setWeatherData(result);
      } catch (e) {
        console.error('Failed to get weather information', e);
        addAlert('danger', 'Failed to load weather information');
        setWeatherData(null);
      }
      setIsLoading(false);
    })();
  }, [
    isLoading,
    weatherData,
    addAlert,
  ]);
 
  const [
    imgNode,
    setImgNode,
  ] = useState<null | HTMLElement>(null);
  const [
    imgNodeHeight,
    setImgNodeHeight,
  ] = useState(555);
  const setImgRef = useCallback(
    (node: HTMLElement | null) => setImgNode(node),
    []
  );
  useEffect(() => {
    if (imgNode === null) {
      return;
    }
 
    const setSize = () => {
      if (imgNode === null) {
        return;
      }
 
      const newWidth = imgNode.clientWidth;
      const ratio = 555 / 815;
      const newHeight = Math.ceil(newWidth * ratio);
      setImgNodeHeight(newHeight);
    };
    setSize();
    imgNode.addEventListener('resize', setSize);
 
    return () => imgNode.removeEventListener('resize', setSize);
  }, [ imgNode, ]);
 
  return <>
    {(typeof weatherData === 'undefined' || isLoading) && <LoadingSpinner />}
    {weatherData === null && <h2 className='text-center'>Failed to Load Weather Data</h2>}
    {weatherData && <>
      <Row>
        <Col xs={12} className='font-monospace text-center'>{weatherData.updated}</Col>
 
        <Col md={6}>
          <h2 className='text-center'>Readiness Level</h2>
          <Col xs={12} className='font-monospace text-center'>
            <table className={styles.table}><tbody>
              <tr>
                <td className='px-2'>National</td>
                <td className='px-2'>{weatherData.readiness.National}</td>
                <td className='px-2'><a href='https://www.nifc.gov/nicc/sitreprt.pdf'>National Sitrep</a></td>
              </tr>
              <tr>
                <td className='px-2'>RM GACC</td>
                <td className='px-2'>{weatherData.readiness.RMA}</td>
                <td className='px-2'><a href='https://gacc.nifc.gov/rmcc/intell.php'>RM GACC Intel</a></td>
              </tr>
            </tbody></table>
          </Col>
 
          <h2 className='text-center mt-5'>Active Fires</h2>
          <Col xs={12} className='font-monospace text-center'>
            <table className={styles.table}>
              <thead><tr>
                <th className='px-2'>Type</th>
                <th className='px-2'>Saguache</th>
                <th className='px-2'>Colorado</th>
              </tr></thead>
              <tbody>
                <tr>
                  <th className='px-2'>New</th>
                  <td className='px-2'>{weatherData.stateFires.new[0]}</td>
                  <td className='px-2'>{weatherData.stateFires.new[1]}</td>
                </tr>
                <tr>
                  <th className='px-2'>Ongoing</th>
                  <td className='px-2'>{weatherData.stateFires.ongoing[0]}</td>
                  <td className='px-2'>{weatherData.stateFires.ongoing[1]}</td>
                </tr>
                <tr>
                  <th className='px-2'>RX</th>
                  <td className='px-2'>{weatherData.stateFires.rx[0]}</td>
                  <td className='px-2'>{weatherData.stateFires.rx[1]}</td>
                </tr>
              </tbody>
            </table>
          </Col>
          <Col xs={12} className='font-monospace'><a href='https://gacc.nifc.gov/rmcc/'>RM GACC Incident Map</a></Col>
          <Col xs={12} className='font-monospace'><a href='https://inciweb.nwcg.gov/'>InciWeb - National Incident Map</a></Col>
 
          <h2 className='text-center mt-5'>Weather Alerts</h2>
          <Col xs={12} className='font-monospace' dangerouslySetInnerHTML={{ __html: weatherData.weather, }} />
          <Col xs={12} className='font-monospace'>
            <a href='https://forecast.weather.gov/MapClick.php?lon=-105.6988059170544&lat=37.9934785363087#.YmFqWPPMIeY'>Crestone 7 Day Forecast</a><br />
            <a href='https://forecast.weather.gov/MapClick.php?w0=t&w3=sfcwind&w3u=1&w4=sky&w5=pop&w6=rh&w13u=0&w14=haines&w15=lal&w16=twind&w16u=1&pqpfhr=6&psnwhr=6&AheadHour=0&Submit=Submit&FcstType=graphical&textField2=-105.6988059170544&textField1=37.9934785363087&site=all&unit=0&dd=&bw='>Crestone Hourly Forecast</a><br />
            <a href='https://www.weather.gov/crh/FWFdisplay?zone=COZ224'>Fire Weather Forecast</a><br />
            <a href='https://www.weather.gov/media/pub/DssPacket.pdf'>Fire Weather Decision Support Packet</a>
          </Col>
 
          <h2 className='text-center mt-5'>Fire Restrictions</h2>
          <Col xs={12} className='font-monospace' dangerouslySetInnerHTML={{ __html: weatherData.bans, }} />
          <Col xs={12} className='font-monospace'><a href='https://www.google.com/maps/d/u/0/embed?mid=1cEAhNHqp82AXABF8qU7k6sRFI4392V0e&ll=38.91583034559255%2C-106.1196738784554&z=7'>Colorado Restriction Map</a></Col>
        </Col>
 
        <Col md={6}>
          <h2 className='text-center'>Fire Weather Maps</h2>
          <h3 className='text-center'>Today</h3>
          <a
            className={styles.imgContainer}
            href='https://www.spc.noaa.gov/products/fire_wx/fwdy1.html'
            style={{
              height: `${imgNodeHeight}px`,
            }}
          >
            <Image
              className={styles.img}
              width={815}
              height={555}
              src='https://www.spc.noaa.gov/products/fire_wx/day1otlk_fire.gif'
              fluid
              alt='Fire weather map for today'
            />
            <svg height='555' width='815' className={`img img-fluid ${styles.img}`} viewBox='0 0 815 555'>
              <circle cx='282' cy='278' r='3' strokeWidth='0' fill='black' />
            </svg>
          </a>
          <Col
            as={Link}
            xs={12}
            className='font-monospace mb-3'
            href='https://www.spc.noaa.gov/products/fire_wx/fwdy1.html'
          >Day 2 Fire Weather Outlook</Col>
 
          <h3 className='text-center'>Tomorrow</h3>
          <a
            className={styles.imgContainer}
            ref={setImgRef}
            href='https://www.spc.noaa.gov/products/fire_wx/fwdy1.html'
            style={{
              height: `${imgNodeHeight}px`,
            }}
          >
            <Image
              className={styles.img}
              width={815}
              height={555}
              src='https://www.spc.noaa.gov/products/fire_wx/day2otlk_fire.gif'
              fluid
              alt='Fire weather map for today'
            />
            <svg height='555' width='815' className={`img img-fluid ${styles.img}`} viewBox='0 0 815 555'>
              <circle cx='282' cy='278' r='3' strokeWidth='0' fill='black' />
            </svg>
          </a>
          <Col
            as={Link}
            xs={12}
            className='font-monospace mb-3'
            href='https://www.spc.noaa.gov/products/fire_wx/fwdy2.html'
          >Day 2 Fire Weather Outlook</Col>
        </Col>
      </Row>
    </>}
  </>;
}