Alejandro Cremades commited on
Commit
dda161c
1 Parent(s): 3b7eb37

Add a button to see more results when needed

Browse files
Middle_School_Card_Search.py CHANGED
@@ -5,9 +5,20 @@ import streamlit_common.lib as lib
5
  import streamlit_common.locale
6
 
7
  mslist_path = "output/middleschool_extra_fields.csv"
8
- number_shown_results = 20
9
  _ = streamlit_common.locale.get_locale()
10
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  st.set_page_config(
12
  page_title="MTG Middle School | Card Search",
13
  page_icon="🃏",
@@ -61,9 +72,20 @@ if results_df.shape[0] < mslist_df.shape[0]:
61
  f'✅ [{cardname}]({lib.compose_scryfall_url(exact_match[1])}) {_["search"]["exact_match"][l]}'
62
  )
63
  st.write(f'**{results_df.shape[0]}**{_["search"]["cards_found"][l]}')
64
- if results_df.shape[0] > number_shown_results:
65
  st.write(_["search"]["top_results"][l])
 
66
  results_df["link"] = results_df["name"].apply(lib.compose_scryfall_url)
67
- results_df[:number_shown_results].transpose().apply(lib.row_to_link)
 
 
 
 
 
 
 
 
 
 
68
 
69
  streamlit_common.footer.write_footer()
 
5
  import streamlit_common.locale
6
 
7
  mslist_path = "output/middleschool_extra_fields.csv"
 
8
  _ = streamlit_common.locale.get_locale()
9
 
10
+ if "number_shown_results" not in st.session_state:
11
+ st.session_state["number_shown_results"] = 20
12
+
13
+
14
+ def add_more_results():
15
+ st.session_state["number_shown_results"] += 20
16
+
17
+
18
+ def reset_more_results():
19
+ st.session_state["number_shown_results"] = 20
20
+
21
+
22
  st.set_page_config(
23
  page_title="MTG Middle School | Card Search",
24
  page_icon="🃏",
 
72
  f'✅ [{cardname}]({lib.compose_scryfall_url(exact_match[1])}) {_["search"]["exact_match"][l]}'
73
  )
74
  st.write(f'**{results_df.shape[0]}**{_["search"]["cards_found"][l]}')
75
+ if results_df.shape[0] > st.session_state["number_shown_results"]:
76
  st.write(_["search"]["top_results"][l])
77
+
78
  results_df["link"] = results_df["name"].apply(lib.compose_scryfall_url)
79
+ results_df[: st.session_state["number_shown_results"]].transpose().apply(
80
+ lib.row_to_link
81
+ )
82
+
83
+ if results_df.shape[0] > st.session_state["number_shown_results"]:
84
+ st.button(label=_["search"]["see_more"][l], on_click=add_more_results)
85
+ if st.session_state["number_shown_results"] > 20:
86
+ st.button(
87
+ label=_["search"]["see_20"][l],
88
+ on_click=reset_more_results,
89
+ )
90
 
91
  streamlit_common.footer.write_footer()
streamlit_common/locale.py CHANGED
@@ -38,6 +38,14 @@ def get_locale():
38
  "en": "Top results:",
39
  "ja": "上位の検索結果:",
40
  },
 
 
 
 
 
 
 
 
41
  },
42
  "check": {
43
  "title": {
 
38
  "en": "Top results:",
39
  "ja": "上位の検索結果:",
40
  },
41
+ "see_more": {
42
+ "en": "See more",
43
+ "ja": "さらに見る",
44
+ },
45
+ "see_20": {
46
+ "en": "Only show 20",
47
+ "ja": "20枚に戻す",
48
+ },
49
  },
50
  "check": {
51
  "title": {