-
Notifications
You must be signed in to change notification settings - Fork 1
Kevin jayat #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Kevin jayat #1
Changes from all commits
4f6560d
fc387fd
9b3b097
0a850c3
ea045c9
8312bd9
e353c31
c182ba7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,13 @@ | ||
| import { Box, Heading, Stack, Text } from '@chakra-ui/react'; | ||
| import { Box, Heading, Stack, Text, Select } from '@chakra-ui/react'; | ||
| import WeatherIcon from './WeatherIcon'; | ||
| import { useWeather } from '../hooks'; | ||
| import { round } from 'lodash'; | ||
| import { formatDate } from '../utils/index'; | ||
|
|
||
| const Sidebar = () => { | ||
| const { data } = useWeather(); | ||
| const today = data?.data?.consolidatedWeather?.[0]; | ||
|
|
||
| return ( | ||
| <Box backgroundColor="gray.800" color="gray.500"> | ||
| <Stack | ||
|
|
@@ -13,19 +19,24 @@ const Sidebar = () => { | |
| > | ||
| <span /> {/* Intentionnaly left blank */} | ||
| <Stack alignItems="center" spacing={0}> | ||
| <WeatherIcon width="100%" /> | ||
| <Select placeholder="Choose your city" variant="flushed"> | ||
| <option value="option1">Lille</option> | ||
| <option value="option2">Lyon</option> | ||
| <option value="option3">Bordeaux</option> | ||
| </Select> | ||
|
Comment on lines
+22
to
+26
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Du coup pour ça, dans AppProvider on a une constante Tu peux l’exposer dans ton contexte, genre <AppContext.Provider value={{
availableCities: CITIES,
selectedCity,
onSelectCity: setSelectedCity
}}>Dans const { availableCities } = useApp();
// [...]
<Select
placeholder="Choose your city"
variant="flushed"
onChange={e => handleSelectCity(e.target.value)}
>
{availableCities.map(({ id, label }) => (
<option key={id} value={id}>
{label}
</option>
))}
</Select>Dans import { useQuery } from 'react-query';
import api from '../api';
import useApp from './useApp';
const useWeather = () => {
const { selectedCity } = useApp();
// const locationId = 608105;
const response = useQuery(
['weather', selectedCity],
() => api.get(`/location/${selectedCity}/`),
{
enabled: Boolean(selectedCity),
},
);
return response;
};
export default useWeather;Quelque chose comme ça. 🎉
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wow merci pour tous ces retours très constructifs et détaillés ! Je m'entrainerai à les appliquer sur l'appli 💯 |
||
| <WeatherIcon width="100%" abbr={today?.weatherStateAbbr} /> | ||
| <Heading as="h1" fontSize="8xl" color="white"> | ||
| 20 | ||
| {Boolean(today?.maxTemp) ? round(today?.maxTemp) : undefined} | ||
| <Text fontSize="4xl" display="inline" color="gray.500"> | ||
| °C | ||
| </Text> | ||
| </Heading> | ||
| <Text fontSize="4xl" display="inline"> | ||
| Sunny | ||
| {today?.weatherStateName} | ||
| </Text> | ||
| </Stack> | ||
| <Stack alignItems="center" spacing={0}> | ||
| <Text>Today • Sun 13 Mar</Text> | ||
| <Text>Today • {formatDate(today?.applicableDate)}</Text> | ||
| <Text>Lille</Text> | ||
| </Stack> | ||
| </Stack> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // ternary operators to determine the angle of the compass | ||
|
|
||
| export function angle(windDirection) { | ||
| try { | ||
| return windDirection == 'N' // direction | ||
| ? 0 // degree | ||
| : windDirection == 'NNE' | ||
| ? 30 | ||
| : windDirection == 'NE' | ||
| ? 50 | ||
| : windDirection == 'ENE' | ||
| ? 70 | ||
| : windDirection == 'E' | ||
| ? 90 | ||
| : windDirection == 'ESE' | ||
| ? 120 | ||
| : windDirection == 'SE' | ||
| ? 140 | ||
| : windDirection == 'SSE' | ||
| ? 160 | ||
| : windDirection == 'S' | ||
| ? 180 | ||
| : windDirection == 'SSW' | ||
| ? 210 | ||
| : windDirection == 'SW' | ||
| ? 230 | ||
| : windDirection == 'WSW' | ||
| ? 250 | ||
| : windDirection == 'W' | ||
| ? 270 | ||
| : windDirection == 'WNW' | ||
| ? 300 | ||
| : windDirection == 'NW' | ||
| ? 320 | ||
| : windDirection == 'NNW' | ||
| ? 340 | ||
| : 0; // goes to 0° if the value is undefined | ||
|
Comment on lines
+5
to
+37
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ici j’ai 3 remarques,
export const angle = windDirection => {
switch (windDirection) {
case 'N':
return 180;
case 'NNE':
return 202.5;
case 'NE':
return 225;
// […]
case 'S':
default:
return 0;
}
} |
||
| } catch (err) { | ||
| return ''; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,9 @@ | ||
| export const formatDate = () => {}; | ||
| import { format } from 'date-fns'; | ||
|
|
||
| export function formatDate(date) { | ||
| try { | ||
| return format(new Date(date), 'eee d MMM'); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🙌 |
||
| } catch (err) { | ||
| return ''; | ||
| } // this date formatting exemple : Fri 18 Mar | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ça fonctionne. Comme on a un Grid au-dessus, on peut aussi utiliser une prop responsive sur le container, pour qu’il n’y ait 2 colonnes dans la grille qu’à partir d’un certain endpoint.