Spaces:
Sleeping
Sleeping
Commit
·
e95c920
1
Parent(s):
cb46f62
Update pages/2_Saved_Recipes.py
Browse files- pages/2_Saved_Recipes.py +13 -1
pages/2_Saved_Recipes.py
CHANGED
@@ -13,18 +13,30 @@ for root, dirs, files in os.walk(directory_path):
|
|
13 |
full_path = os.path.join(root, file)
|
14 |
f = open(full_path)
|
15 |
recipe_json = json.load(f)
|
|
|
16 |
recipes.append(recipe_json)
|
17 |
|
18 |
#st.json(saved_files)
|
19 |
|
20 |
-
|
|
|
|
|
|
|
|
|
21 |
st.write("") # just some space
|
22 |
|
23 |
recipes_filtered = [x for x in recipes if user_search.lower() in x['name'].lower()]
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
for recipe in recipes_filtered:
|
26 |
with st.expander(recipe['name']):
|
27 |
st.markdown(recipe['md'])
|
|
|
28 |
|
29 |
|
30 |
# ignore
|
|
|
13 |
full_path = os.path.join(root, file)
|
14 |
f = open(full_path)
|
15 |
recipe_json = json.load(f)
|
16 |
+
recipe_json['file'] = file
|
17 |
recipes.append(recipe_json)
|
18 |
|
19 |
#st.json(saved_files)
|
20 |
|
21 |
+
cols = st.columns([5, 1])
|
22 |
+
with cols[0]:
|
23 |
+
user_search = st.text_input("Search Recipes", value="")
|
24 |
+
with cols[1]:
|
25 |
+
user_sort = st.selectbox("Sort", ('A-Z', 'Z-A', 'Random'))
|
26 |
st.write("") # just some space
|
27 |
|
28 |
recipes_filtered = [x for x in recipes if user_search.lower() in x['name'].lower()]
|
29 |
+
if user_sort == 'A-Z':
|
30 |
+
recipes_filtered.sort(key=lambda x: x['name'])
|
31 |
+
elif user_sort == 'Z-A':
|
32 |
+
recipes_filtered.sort(key=lambda x: x['name'], reverse=True)
|
33 |
+
elif user_sort == 'Random':
|
34 |
+
recipes_filtered.sort(key=lambda x: x['file'])
|
35 |
|
36 |
for recipe in recipes_filtered:
|
37 |
with st.expander(recipe['name']):
|
38 |
st.markdown(recipe['md'])
|
39 |
+
st.write(recipe['file'])
|
40 |
|
41 |
|
42 |
# ignore
|