Skip to content

Commit

Permalink
Weather App (#635)
Browse files Browse the repository at this point in the history
* Weather App

* cleanup

* Removing consoles

* Cleanup
  • Loading branch information
cyberviking5 authored Oct 4, 2023
1 parent 8eb6cf7 commit 9bd4642
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 3 deletions.
1 change: 0 additions & 1 deletion packages/kitchen-sink/src/examples/redux-todo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ const MainTodoApp = block(() => {
const TodoApp = () => {
const [input, setInput] = useState('');


const count = useSelector(
(state: { todo: typeof initialState }) => state.todo.count,
);
Expand Down
149 changes: 149 additions & 0 deletions packages/kitchen-sink/src/examples/weather-app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
import styled from 'styled-components';
import { useState } from 'react';
import React from 'react';
import { block } from 'million/react';

const Condition = styled.span`
margin: 20px auto;
text-transform: capitalize;
font-size: 14px;
& span {
font-size: 28px;
}
`;

const SearchBox = styled.form`
display: flex;
flex-direction: row;
justify-content: space-evenly;
margin: 20px;
border: black solid 1px;
border-radius: 2px;
& input {
padding: 10px;
font-size: 14px;
border: none;
outline: none;
font-family: Montserrat;
font-weight: bold;
}
& button {
background-color: blue;
font-size: 14px;
padding: 0 10px;
color: white;
border: none;
outline: none;
cursor: pointer;
font-family: Montserrat;
font-weight: bold;
}
`;
const ChooseCityLabel = styled.span`
color: white;
margin: 10px auto;
font-size: 18px;
font-weight: bold;
`;
const WelcomeWeatherLogo = styled.img`
width: 140px;
height: 140px;
margin: 40px auto;
`;

type Weather = {
city: string;
weatherDesc: string | undefined;
temp: any;
};

const WeatherComponent = block(({ city, weatherDesc, temp }: Weather) => {
return (
<div>
<Condition>
<span>
{typeof temp === 'number' ? (
<Condition>
<span>{`${Math.floor(temp - 273)}°C`}</span>
</Condition>
) : (
<h1>NOT DEFINED</h1>
)}
</span>
{` | ${weatherDesc}`}
</Condition>
<h3 style={{ textAlign: 'center' }}>{city.toUpperCase()}</h3>
</div>
);
});

export default function Weather() {
const [city, updatecity] = useState<string | null>(null);
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
updatecity(event.target.value);
};
const [weather, updateWeather] = useState();
const [temp, updatetemp] = useState();
const [weatherDesc, updateWeatherDesc] = useState();
const fetchWeather = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
const response = await fetch(
`https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=fe4feefa8543e06d4f3c66d92c61b69c`,
);
const data = await response.json();
updateWeather(data.weather[0].main);
updateWeatherDesc(data.weather[0].description);
updatetemp(data.main.temp);
};
return (
<div
style={{
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
width: '380px',
padding: '20px 10px',
margin: 'auto',
borderRadius: '4px',
background: '#252525',
fontFamily: 'Montserrat',
color: 'white',
}}
>
<span
style={{
color: 'white',
margin: '20px auto',
fontSize: '18px',
fontWeight: 'bold',
}}
>
Weather App
</span>
{city && weather ? (
<>
<WeatherComponent city={city} weatherDesc={weatherDesc} temp={temp} />
</>
) : (
<>
<WelcomeWeatherLogo
src={
'https://ayushkul.github.io/react-weather-app/icons/perfect-day.svg'
}
/>
<ChooseCityLabel>Find Weather of your city</ChooseCityLabel>
<SearchBox
onSubmit={async (e) => {
e.preventDefault();
await fetchWeather(e);
}}
>
<input onChange={handleChange} placeholder="City" />
<button type={'submit'}>Search</button>
</SearchBox>
</>
)}
</div>
);
}
10 changes: 8 additions & 2 deletions packages/kitchen-sink/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ type Module = { default: ComponentType<any> };
Object.entries(import.meta.glob('./examples/*.{tsx,jsx}')).map(
async ([key, mod]) =>
[
key.replace('./examples/', '').replace('.tsx', '').replace('.jsx', ''),
key
.replace('./examples/', '')
.replace('.tsx', '')
.replace('.jsx', ''),
mod as () => Promise<Module>,
] as const,
),
Expand Down Expand Up @@ -67,7 +70,10 @@ type Module = { default: ComponentType<any> };
key={key}
disabled={hasSelected && selected === index}
>
{key.replace('./examples/', '').replace('.tsx', '').replace('.jsx', '')}
{key
.replace('./examples/', '')
.replace('.tsx', '')
.replace('.jsx', '')}
</button>
);
})}{' '}
Expand Down

2 comments on commit 9bd4642

@vercel
Copy link

@vercel vercel bot commented on 9bd4642 Oct 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

million-kitchen-sink – ./packages/kitchen-sink

million-kitchen-sink-millionjs.vercel.app
million-kitchen-sink.vercel.app
million-kitchen-sink-git-main-millionjs.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 9bd4642 Oct 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

sink – ./packages/kitchen-sink

sink-git-main-millionjs.vercel.app
sink-millionjs.vercel.app
million-kitchen-sink-atit.vercel.app
sink.million.dev

Please sign in to comment.