Skip to content

Commit 897621a

Browse files
authored
Merge pull request #6 from reactplay/Aug-3-sync
update as per 3/8
2 parents 3b24558 + 585f5a1 commit 897621a

File tree

114 files changed

+14158
-190
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+14158
-190
lines changed

src/analog-clock/AnalogClock.jsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
import { getPlayById } from "meta/play-meta-util";
21
import "./AnalogClock.css";
32

43
import PlayHeader from "common/playlists/PlayHeader";
5-
import { useState } from "react";
6-
import { useEffect } from "react";
4+
import { useState, useEffect } from "react";
75

86
function AnalogClock(props) {
9-
// Do not remove the below lines.
10-
// The following code is to fetch the current play from the URL
11-
const { id } = props;
12-
const play = getPlayById(id);
137

148
// Your Code Start below.
9+
1510
const [date, setDate] = useState(new Date());
1611
useEffect(() => {
1712
const interval = setInterval(() => {
@@ -27,7 +22,7 @@ function AnalogClock(props) {
2722
return (
2823
<>
2924
<div className="play-details">
30-
<PlayHeader play={play} />
25+
<PlayHeader play={props} />
3126
<div className="play-details-body">
3227
{/* Your Code Starts Here */}
3328
<h1 className="clock-play-heading">Analog Clock</h1>

src/calendar/Calendar.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as React from 'react';
2-
import { getPlayById } from 'meta/play-meta-util';
32

43
import PlayHeader from 'common/playlists/PlayHeader';
54
import CalendarGrid from './CalendarGrid'
@@ -9,17 +8,13 @@ import './Calendar.scss'
98
import ModalContainer from './ModalContainer';
109

1110
function Calendar(props:any) {
12-
// Do not remove the below lines.
13-
// The following code is to fetch the current play from the URL
14-
const { id } = props;
15-
const play = getPlayById(id);
1611

1712
// Your Code Start below.
1813

1914
return (
2015
<>
2116
<div className="play-details">
22-
<PlayHeader play={play} />
17+
<PlayHeader play={props} />
2318
<div className="play-details-body calendar-play">
2419
<ContextProvider>
2520
<ModalContainer />

src/clock/CurrentTimer.jsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11

22
import PlayHeader from 'common/playlists/PlayHeader';
33
import { useEffect, useState } from 'react';
4-
import { getPlayById } from 'meta/play-meta-util';
54

65
import "./clock.css";
76

87
const CurrentTimer = (props) => {
9-
// The following code is to fetch the current play from the URL
10-
const { id } = props;
11-
const play = getPlayById(id);
128

139
// Create a real-time date time counter
1410
const [date, setDate] = useState(new Date());
@@ -24,7 +20,7 @@ const CurrentTimer = (props) => {
2420
return(
2521
<>
2622
<div className="play-details">
27-
<PlayHeader play={play} />
23+
<PlayHeader play={props} />
2824
<div className="play-details-body">
2925
<div className="counter">
3026
<h2>Current Time</h2>
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import { createContext, useEffect, useState } from "react";
2+
import PlayHeader from "common/playlists/PlayHeader";
3+
import "./contextWithRealUsecases.css";
4+
import ContextInfoSlider from "./components/ContextInfoSlider";
5+
import Heading from "./components/Heading";
6+
import Menu from "./components/Menu";
7+
import Main from "./components/Main/Main";
8+
import Recipes from "./Recipes";
9+
import CuisineContext from "./context/CuisineContext";
10+
11+
function ContextWithRealUsecases(props) {
12+
// Your Code Start below.
13+
14+
const [activeCuisine, setActiveCuisine] = useState(null);
15+
16+
//slide index
17+
const [index, setIndex] = useState(0);
18+
19+
const activeCuisineHandler = (cuisine) => {
20+
setActiveCuisine(cuisine);
21+
};
22+
23+
//get an array of cuisines
24+
const cuisines = Recipes.map((item) => {
25+
return item.recipe.cusine;
26+
});
27+
28+
//remove duplicate cuisines.
29+
const uniqCuisines = [...new Set(cuisines)];
30+
31+
//get recipes filtered by cuisine type
32+
const recipesByCusine = Recipes.filter(
33+
(item) => item.recipe.cusine === activeCuisine
34+
);
35+
36+
//prev slide
37+
const handlePrev = () => {
38+
if (index > 1) {
39+
setIndex(index - 1);
40+
} else setIndex(5);
41+
};
42+
43+
//next slide
44+
const handleNext = () => {
45+
if (index < 5) {
46+
setIndex(index + 1);
47+
} else setIndex(1);
48+
};
49+
50+
//As the we click the menu, it will change the slider
51+
useEffect(() => {
52+
handleNext();
53+
}, [activeCuisine]);
54+
return (
55+
<>
56+
<div className="play-details">
57+
<PlayHeader play={props} />
58+
<div className="play-details-body">
59+
{/* Your Code Starts Here */}
60+
<div className="context-with-real-usecases">
61+
<h1 className="context-with-real-usecases main-heading">
62+
React Context
63+
</h1>
64+
65+
<CuisineContext.Provider
66+
value={{
67+
activeCuisine,
68+
activeCuisineHandler,
69+
uniqCuisines,
70+
recipesByCusine,
71+
index,
72+
handlePrev,
73+
handleNext,
74+
}}
75+
>
76+
<ContextInfoSlider />
77+
<Heading />
78+
{activeCuisine === null ? <Menu /> : <Main />}
79+
</CuisineContext.Provider>
80+
</div>
81+
{/* Your Code Ends Here */}
82+
</div>
83+
</div>
84+
</>
85+
);
86+
}
87+
88+
export default ContextWithRealUsecases;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# context-with-real-usecases
2+
3+
I was learning contextAPI and was bored to learn the same counter or toggle example and hence i decided to make something that feel real.
4+
5+
`context-with-real-usecases` is a recipe app that lists the recipes by cuisine type. Based on the selected cuisine app shows the list of recipes, the selected cusine and the cusine fact.
6+
7+
## Play Demographic
8+
9+
- Language: js
10+
- Level: Intermediate
11+
12+
## Creator Information
13+
14+
- User: Deepak8717
15+
- Gihub Link: https://github.com/Deepak8717
16+
- Blog:
17+
- Video:
18+
19+
## Implementation Details
20+
21+
App include several components like `<ContextInfoSlider />`, `<Heading />`,`<Menu />`,`<Main />` if we go futher `<Heading />` includes another component called `<CuisineModal />` and `<Main />`include another called `<RecipeGrid />`. Since they all need the `activeCuisine` to show the relative information it would be difficult to prop drill. Hence we have used contextAPI.
22+
23+
## Consideration
24+
25+
Update all considerations(if any)
26+
27+
## Resources
28+
29+
Update external resources(if any)
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
const Recipes = [
2+
{
3+
recipe: {
4+
url: "https://www.awesomecuisine.com/wp-content/uploads/2014/03/chicken-tikka.jpg",
5+
title: "Chicken Tikka",
6+
vegan: "non-veg",
7+
mealtype: "snacks",
8+
cusine: "Indian",
9+
price: "20",
10+
randomfact: "India is the Spice Capital of the World",
11+
},
12+
},
13+
{
14+
recipe: {
15+
url: "https://upload.wikimedia.org/wikipedia/commons/thumb/c/cf/Biryani_of_Lahore.jpg/640px-Biryani_of_Lahore.jpg",
16+
title: "Biryani",
17+
vegan: "veg",
18+
mealtype: "lunch",
19+
cusine: "Indian",
20+
price: "15",
21+
randomfact:
22+
"As per Ayurveda, India’s ancient medicinal system, there are three primary categories of food – Satvic, Rajasic and Tamasic.",
23+
},
24+
},
25+
{
26+
recipe: {
27+
url: "https://bigoven-res.cloudinary.com/image/upload/t_recipe-256/dal-makhani-how-to-make-dal-makhani-2258046.jpg",
28+
title: "Dal Makhani",
29+
vegan: "veg",
30+
mealtype: "Dinner",
31+
cusine: "Indian",
32+
price: "12",
33+
randomfact:
34+
"India is home to bhot jolokia, one of the hottest chillies in the world. Also called “ghost chilli”, ",
35+
},
36+
},
37+
{
38+
recipe: {
39+
url: "https://food.fnr.sndimg.com/content/dam/images/food/fullset/2019/10/9/DV3016_masala-dosa_s4x3.jpg.rend.hgtvcom.406.305.suffix/1570635680579.jpeg",
40+
title: "Dosha",
41+
vegan: "veg",
42+
mealtype: "Breakfast",
43+
cusine: "Indian",
44+
price: "16",
45+
randomfact: "Indian people use their hands to eat",
46+
},
47+
},
48+
{
49+
recipe: {
50+
url: "https://imagesvc.meredithcorp.io/v3/mm/image?q=60&c=sc&poi=face&w=1600&h=800&url=https%3A%2F%2Fstatic.onecms.io%2Fwp-content%2Fuploads%2Fsites%2F43%2F2020%2F09%2F21%2F290890_original.jpg",
51+
title: "Kung Pao Chicken",
52+
vegan: "Non-veg",
53+
mealtype: "Lunch",
54+
cusine: "Chinese",
55+
price: "14",
56+
randomfact: "China is the homeland of tea.",
57+
},
58+
},
59+
{
60+
recipe: {
61+
url: "https://previews.123rf.com/images/iphotoshot/iphotoshot1203/iphotoshot120300010/12882609-disk-of-soybean-milk-and-deep-fried-dough-stick-for-breakfast.jpg",
62+
title: "Soybean Milk and Deep-Fried Dough Sticks",
63+
vegan: "veg",
64+
mealtype: "Lunch",
65+
cusine: "Chinese",
66+
price: "10",
67+
randomfact:
68+
"Chinese don't eat with knives and forks, traditionally, which is seen as violent or barbaric, but with chopsticks",
69+
},
70+
},
71+
{
72+
recipe: {
73+
url: "https://mamalovestocook.com/wp-content/uploads/2020/05/boiled-dumplings-480x480.jpg",
74+
title: "dumplings",
75+
vegan: "Non-veg",
76+
mealtype: "Dinner",
77+
cusine: "Chinese",
78+
price: "18",
79+
randomfact:
80+
"Fortune Cookie was invented in California, as a variation of Japanese “omikuji senbei” fortune cookies. The main difference of Fortune Cookies is that they are much sweeter than Japanese variant.",
81+
},
82+
},
83+
{
84+
recipe: {
85+
url: "http://www.ecns.cn/2016/03-16/U472P886T1D203169F12DT20160316132624.jpg",
86+
title: "Latito",
87+
vegan: "veg",
88+
mealtype: "snack",
89+
cusine: "Chinese",
90+
price: "8",
91+
randomfact:
92+
"Ancient Chinese were very interested in food preservation methods",
93+
},
94+
},
95+
{
96+
recipe: {
97+
url: "https://ca-times.brightspotcdn.com/dims4/default/fbdb510/2147483647/strip/true/crop/1154x721+63+0/resize/1044x652!/quality/90/?url=https%3A%2F%2Fcalifornia-times-brightspot.s3.amazonaws.com%2F62%2F5d%2Ffe1b17ccdd32e48540720225cc19%2Fkikyd4nc-recipe-db",
98+
title: "Soupe à l'oignon",
99+
vegan: "Non-veg",
100+
mealtype: "breakfast",
101+
cusine: "French",
102+
price: "18",
103+
randomfact: "French fries… are not French!",
104+
},
105+
},
106+
{
107+
recipe: {
108+
url: "https://sf2.viepratique.fr/wp-content/uploads/sites/2/2013/11/blanquette-de-veau-e1457428254753.jpg",
109+
title: "Blanquette De Veau ",
110+
vegan: "Non-veg",
111+
mealtype: "Lunch",
112+
cusine: "French",
113+
price: "25",
114+
randomfact:
115+
"Approximately 500,000,000 snails are eaten in France per year",
116+
},
117+
},
118+
{
119+
recipe: {
120+
url: "https://www.curiouscuisiniere.com/wp-content/uploads/2015/10/French-Onion-Soup-2731.21.jpg.webp",
121+
title: "Soupe À l’oignon",
122+
vegan: "veg",
123+
mealtype: "Dinner",
124+
cusine: "French",
125+
price: "30",
126+
randomfact:
127+
"French people love alcohol so much that they drink some before and after the meal",
128+
},
129+
},
130+
{
131+
recipe: {
132+
url: "https://www.yumcurry.com/wp-content/uploads/2020/06/pizza-margherita-recipe-500x375.jpg",
133+
title: "margherita",
134+
vegan: "Non-veg",
135+
mealtype: "breakfast",
136+
cusine: "Italian",
137+
price: "30",
138+
randomfact: "Pizza was invented in Italy, in Naples",
139+
},
140+
},
141+
{
142+
recipe: {
143+
url: "https://cdn.loveandlemons.com/wp-content/uploads/2021/11/minestrone-soup-500x500.jpg",
144+
title: "Minestrone",
145+
vegan: "Non-veg",
146+
mealtype: "Dinner",
147+
cusine: "Italian",
148+
price: "25",
149+
randomfact:
150+
"An Italian eat an average of 23 kg (51 lbs) of pasta per year",
151+
},
152+
},
153+
];
154+
155+
export default Recipes;

0 commit comments

Comments
 (0)