Skip to content

Commit

Permalink
About pop-up
Browse files Browse the repository at this point in the history
  • Loading branch information
jonlucasoffice committed Jan 27, 2023
1 parent 7a33d08 commit 5943ad5
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 27 deletions.
18 changes: 17 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,32 @@ import { MapBox } from './components/Map';
import { Crosshair } from './components/Crosshair';
import { LngLatLike } from 'mapbox-gl';
import { MainMenu } from './components/Menus';
import { About } from './components/About';

export const App = () => {

const [lnglat, setLngLat] = useState<LngLatLike>({lng: -70.9, lat: 42.35});
const [aqi, setAQI] = useState();

const [userHasInteracted, setUserHasInteracted] = useState(false);
const [toggleAbout, setToggleAbout] = useState(true);

return (
<>
<Header />
<MapBox lnglat={lnglat} setLngLat={setLngLat} setAQI={setAQI}/>
{toggleAbout && (
<About
toggleAbout
setToggleAbout={setToggleAbout}
setUserHasInteracted={setUserHasInteracted}
/>
)}
<MapBox
lnglat={lnglat}
setLngLat={setLngLat}
setAQI={setAQI}
userHasInteracted={userHasInteracted}
/>
<MainMenu lnglat={lnglat} aqi={aqi} />
<Crosshair />
</>
Expand Down
8 changes: 4 additions & 4 deletions src/apis/aqi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ export async function getAQIValues(lnglat) {
} else {
let data = resp.response.data
let aqiValues = {}
aqiValues["o3"] = data.iaqi.h.v
aqiValues["humidity"] = data.iaqi.h.v
aqiValues["co"] = data.iaqi.co.v
aqiValues["pm25"] = data.iaqi.pm25.v
aqiValues["o3"] = data.iaqi.so3?.v
aqiValues["humidity"] = data.iaqi.h?.v
aqiValues["co"] = data.iaqi.co?.v
aqiValues["pm25"] = data.iaqi.pm25?.v
return aqiValues;
}
}
19 changes: 19 additions & 0 deletions src/components/About/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from "react";
import { BasicButton } from "../Buttons";
import "./style.css";

export const About = ({ toggleAbout, setToggleAbout, setUserHasInteracted }) => {

const handleClick = () => {
setUserHasInteracted(true)
setToggleAbout((current) =>(!current))
}

return (
<div className="module">
<p>Air quality you can hear.</p>
<p>Sound Vane leverages utilities from the World Air Quality Index Project. To learn more about the project, make sure to visit their site here: https://aqicn.org/</p>
<BasicButton onClick={handleClick} text="Listen" />
</div>
)
}
15 changes: 15 additions & 0 deletions src/components/About/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.module {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
z-index: 9;
width:100%;
max-width: 500px;
padding: 1.5rem;
-webkit-backdrop-filter: blur(10px);
backdrop-filter: blur(10px);
background-color: hsla(0 , 0%, 100% ,0.7);
border-radius: 10px;
text-align: center;
}
3 changes: 1 addition & 2 deletions src/components/Crosshair/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ import React from "react";
import "./style.css";

export const Crosshair = () => {
return <div className="crosshair">
</div>
return <div className="crosshair"></div>
}
10 changes: 9 additions & 1 deletion src/components/Crosshair/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@
width: 70px;
height: 70px;
border-radius: 100%;
border: 3px solid var(--purple);
border: 3px dashed var(--purple);
z-index: 2;
pointer-events: none;
animation:spin 30s linear infinite;
}

@keyframes spin {
100% {
-webkit-transform: translate(-50%, -50%) rotateZ(360deg);
transform:translate(-50%, -50%) rotateZ(360deg);
}
}
8 changes: 4 additions & 4 deletions src/components/Map/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { getAQIValues } from '../../apis/aqi';

mapboxgl.accessToken = process.env.REACT_APP_MAPBOX;

export const MapBox = ({ lnglat, setLngLat, setAQI }) => {
export const MapBox = ({ lnglat, setLngLat, setAQI, userHasInteracted }) => {
const mapContainer = useRef(null);
const [zoom, setZoom] = useState(9);
const [zoom, setZoom] = useState(4);

useEffect(() => {
const map = new mapboxgl.Map({
Expand All @@ -32,9 +32,9 @@ export const MapBox = ({ lnglat, setLngLat, setAQI }) => {

useEffect(() => {
getAQIValues(lnglat).then((result) => {
setAQI(result)
userHasInteracted && setAQI(result)
})
}, [lnglat, setAQI]);
}, [lnglat, setAQI, userHasInteracted]);

return (
<div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Player/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const Player = ({lnglat, aqi}) => {
<>
<SheetMusic RelativeAQI={getRelativeAQI(aqi)} />
<MetricsAQI aqi={aqi} />
<Synth RelativeAQI={getRelativeAQI(aqi)} />
<Synth aqi={aqi} RelativeAQI={getRelativeAQI(aqi)} />
</>
}
</div>
Expand Down
26 changes: 12 additions & 14 deletions src/components/Synth/index.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
import { useState, useEffect } from "react";
// import * as Tone from "tone";
// import { PlayButton } from "../Buttons";
import "./style.css";

export const Synth = ({RelativeAQI}) => {
export const Synth = ({aqi, RelativeAQI}) => {

const [isPlaying, setIsPlaying] = useState(false)

const baseNotes = ["c", "e", "g", "b"];
const accidentals = Object.values(RelativeAQI)

const notes = baseNotes.map((note, index) => (
note + "-" + accidentals[index]
))

const playNote = (note) => {

let player = document.createElement('audio');
Expand All @@ -25,8 +16,15 @@ export const Synth = ({RelativeAQI}) => {
})
}

const playSequence = () => {
const playSequence = (RelativeAQI) => {

const baseNotes = ["c", "e", "g", "b"];
const accidentals = Object.values(RelativeAQI)

const notes = baseNotes.map((note, index) => (
note + "-" + accidentals[index]
))

let i = 0;

function loop() {
Expand All @@ -45,13 +43,13 @@ export const Synth = ({RelativeAQI}) => {
}

useEffect(() => {

if (!isPlaying) {
setIsPlaying(true)
playSequence()
playSequence(RelativeAQI)
}

},[RelativeAQI]);
},[aqi]);

return (
<>
Expand Down

0 comments on commit 5943ad5

Please sign in to comment.