-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathelephantgraveyard.txt
executable file
·248 lines (198 loc) · 7.37 KB
/
elephantgraveyard.txt
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
notes:
How I originally fetched recipes using get static props.
This is server side rendering.
I moved away from this on Monday 2/15 or Tuesday
// MUST USE ABSOLUTE PATH FOR THIS TO WORK
// export async function getStaticProps(context) {
// const res = await fetch('http://localhost:5000/api/recipes')
// const recipeData24 = await res.json()
// if (!recipeData24) {
// return {
// notFound: true,
// }
// }
// return {
// props: {recipeData24,}, // will be passed to the page component as props
// }
// }
Tried this but couldn't get it to work, gave up on it earlier this wee
Thursday 2/18
// Split title on the word if awkward 2 liner
let recipeTitle = props.title;
if (recipeTitle.length > 31 && recipeTitle.length < 43) {
let titleSplit = recipeTitle.split(" ");
let count = 0;
let spliceIndex = 0;
for (let i=0; i< titleSplit.length; i++) {
count += titleSplit[i].length;
if (count>20) {
spliceIndex = i;
break;
}
}
titleSplit.splice(spliceIndex, 0, '{"\n"}');
recipeTitle = titleSplit.join(" ");
}
// MUST USE ABSOLUTE PATH FOR THIS TO WORK
// fetch returns a promise to get the data
// data is an http Response object promise <> Response
// await is keyword to allow you to await a promise
// This is the static way to fetch data, Today is Day 9 on this project
// Need to evolve.
// export async function getStaticProps(context) {
// const res = await fetch('http://localhost:5000/api/recipes')
// const recipeData24 = await res.json()
// if (!recipeData24) {
// return {
// notFound: true,
// }
// }
// return {
// props: {recipeData24} // will be passed to the page component as props
// }
// }
// Resource: Codecademy.com React
// const options = ["Bell Pepper", "Sausage", "Pepperoni", "Pineapple"];
// export default function PersonalPizza() {
// const [selected, setSelected] = useState([]);
// const toggleTopping = ({target}) => {
// const clickedTopping = target.value;
// setSelected((prev) => {
// // check if clicked topping is already selected
// if (prev.includes(clickedTopping)) {
// // filter the clicked topping out of state
// return prev.filter(t => t !== clickedTopping);
// } else {
// // add the clicked topping to our state
// return [clickedTopping, ...prev];
// }
// });
// };
// return (
// <div>
// {options.map(option => (
// <button value={option} onClick={toggleTopping} key={option}>
// {selected.includes(option) ? "Remove " : "Add "}
// {option}
// </button>
// ))}
// <p>Order a {selected.join(", ")} pizza</p>
// </div>
// );
// }
//fetch('/recipes_data') -> Promise<response>
// This is going to fetch the data and it's going to wait until it's fetched.
export default function Home(props) {
// best place to fetch data because it's called right away
const fetcher3 = url => fetch(url).then(r => r.json())
let user_id = 1;
// useSWR takes 2 parameters: the URL, and how to fetch it (.then promise)
// beneath the hood useSWR has 1 object with 2 keys returned, data and error
// we call this destructuring :)
const { data, error } = useSWR(`/api/users/${user_id}/recipes`, fetcher3)
if (error) return <div>failed to load</div>
if (!data) return <div>loading...</div>
// DON'T EVEN NEED THIS
// // return object with key props and value recipe data so you can just use props. from now on
// return {
// props: {recipeData24}
// };
// // I self called this so I won't have to call it right afterward. :)
// MUST USE ABSOLUTE PATH FOR THIS TO WORK
// EVOLVED MY CODE 2/17/21 11:00 PM
// export async function getStaticProps(context) {
// const res = await fetch('http://localhost:5000/api/recipes')
// const recipeData24 = await res.json()
// if (!recipeData24) {
// return {
// notFound: true,
// }
// }
// return {
// props: {recipeData24,}, // will be passed to the page component as props
// }
// }
// OLD CODE THAT DIDN'T TALK TO BACKEND
// this sets the state for my selected recipes (adds/ removes)
// setFavorite((favorite) => {
// if (favorite == true) {
// console.log("This was a favorited recipe, but now it isnt!")
// console.log(props)
// }
// if (favorite == false) {
// console.log("This was not a favorited recipe. Now it is!")
// }
# Bring to my server post request
# Make sure my component renders that post request
# Build a component that will be redirected to that holds the results
# Do this first then get text message going
# Then get venmo modal going
# Last week thing: Security before deployment
# OAuth - Google, not easy or straight forward
# search_variable = '%{}%'.format(search_phrase)
# print("This is my search variable:", search_variable)
#https://stackoverflow.com/questions/3325467/sqlalchemy-equivalent-to-sql-like-statement
Replaced this with map method on array 3/7 [tag_id].js
// const recipeCards = [];
// for (const recipe of props.recipeData24) {
// recipeCards.push(
// <RecipeCard
// title={recipe.title}
// directions={recipe.directions}
// img={recipe.img}
// recipe_id={recipe.recipe_id}
// />
// );
// }
Replaced this with map method on array 3/7 index.js
const recipeCards = [];
for (const recipe of props.recipeData48) {
recipeCards.push(
<RecipeTile
title={recipe.title}
directions={recipe.directions}
recipe_id={recipe.recipe_id}
img={recipe.img}
/>
);
}
Replaced this with map metho 3/7 personalizedgrocerylist.js
// let options = [];
// for (const recipe of props.userRecipesData) {
// options.push(recipe.title);
// }
Replaced Nav Bar with bootstrap Nav Bar 3/9
{/* THIS IS WITHOUT BOOTSTRAP!!! - CHANGED 3/9/21
<nav id="top-nav">
<div className={styles['nav-left']}>
<Link href="/"><a><img src="http://localhost:5000/static/img/logo.png" alt="My TJ's Run Logo" height="40px" /></a></Link>
<button className={styles['left']} id={styles['get-started-button']} type="button" onClick={(e) => { e.preventDefault(); router.push('/myrecipes'); }}>
{bookicon} My Recipes
</button>
<button className={styles['left']} id={styles['get-started-button']} type="button" onClick={(e) => { e.preventDefault(); router.push('/mygrocerylist'); }}>
{ basketicon } { smsicon } My Grocery List
</button>
</div>
<div className={styles['nav-right']}>
<form onSubmit={handleSearch} className={styles['search-form']}>
<input type="text"
placeholder="Search"
name="search_string"
autoComplete="off"
required />
<button className={styles['search-button']} type="submit">
{searchicon}
</button>
</form>
<button
className={styles['right']}
type="button"
title="Find a Trader Joe's"
onClick={(e) => { e.preventDefault(); router.push('/storelocator');
}}>
{ searchlocationicon }
</button>
{ welcome }
{ logInOrOut }
</div>
</nav> */}