-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLibraryContext.js
60 lines (50 loc) · 1.87 KB
/
LibraryContext.js
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
import React, {createContext, useState} from "react";
//Sories
import Ascultarea from './AllStorys/Ascultarea';
import Minciunica from "./AllStorys/Minciunica";
const LibraryContext = createContext();
export function LibraryProvider ({children}) {
const [userStories, setUserStories] = useState([
{
name: 'Ascultarea',
description: 'O scurta povestioara care subliniaza importanta ascultarii de parinti. si cum ascultand de parinti aduce mereu lucruri bune',
price: 0,
id: 1,
age: '4+',
thumbnail: require('./stories/Ascultarea/images/1.png'),
story: <Ascultarea/>
},
{
name: 'Consecinta Minciunii',
description: 'O scurta povestioara din care invatam ca minciuna aduce consecinte grave. Vedem cum miniuna spusa chair si in gluma aduce probleme.',
price: 0,
id: 2,
age: '5+',
thumbnail: require('./stories/Minciuna/images/1.png'),
story: <Minciunica/>
},
]);
const addStory = (name, description, price, age, thumbnail, story) => {
//make copy of userStories
const newUserStory = userStories;
//create newStory with variable provided
const newStory = {
name: name,
description: description,
price: price,
id: userStories.length + 1,
age: age,
thumbnail: thumbnail,
story: story
}
//add the newStory to copy userStories
newUserStory.push(newStory);
//set userStories the copy list
setUserStories(newUserStory);
alert('Thank you for buying from us.')
}
return(
<LibraryContext.Provider value={{userStories, setUserStories, addStory}}>{children}</LibraryContext.Provider>
)
}
export default LibraryContext;