Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -173,7 +173,7 @@ def get_pet_details(pet_id):
|
|
173 |
return None
|
174 |
|
175 |
# Function to format pet card
|
176 |
-
def display_pet_card(pet, is_favorite=False):
|
177 |
col1, col2 = st.columns([1, 2])
|
178 |
|
179 |
with col1:
|
@@ -224,20 +224,18 @@ def display_pet_card(pet, is_favorite=False):
|
|
224 |
|
225 |
col1, col2 = st.columns(2)
|
226 |
with col1:
|
227 |
-
if st.button("View Details", key=f"details_{pet['id']}"):
|
228 |
-
|
229 |
-
|
230 |
-
st.rerun() # Force immediate rerun
|
231 |
-
|
232 |
with col2:
|
233 |
if not is_favorite:
|
234 |
-
if st.button("Add to Favorites", key=f"fav_{pet['id']}"):
|
235 |
if pet['id'] not in [p['id'] for p in st.session_state.favorites]:
|
236 |
st.session_state.favorites.append(pet)
|
237 |
st.success(f"Added {pet['name']} to favorites!")
|
238 |
st.rerun()
|
239 |
else:
|
240 |
-
if st.button("Remove from Favorites", key=f"unfav_{pet['id']}"):
|
241 |
st.session_state.favorites = [p for p in st.session_state.favorites if p['id'] != pet['id']]
|
242 |
st.success(f"Removed {pet['name']} from favorites!")
|
243 |
st.rerun()
|
|
|
173 |
return None
|
174 |
|
175 |
# Function to format pet card
|
176 |
+
def display_pet_card(pet, is_favorite=False, context="search"):
|
177 |
col1, col2 = st.columns([1, 2])
|
178 |
|
179 |
with col1:
|
|
|
224 |
|
225 |
col1, col2 = st.columns(2)
|
226 |
with col1:
|
227 |
+
if st.button("View Details", key=f"details_{context}_{pet['id']}"):
|
228 |
+
st.session_state.selected_pet = pet['id']
|
229 |
+
st.stop()
|
|
|
|
|
230 |
with col2:
|
231 |
if not is_favorite:
|
232 |
+
if st.button("Add to Favorites", key=f"fav_{context}_{pet['id']}"):
|
233 |
if pet['id'] not in [p['id'] for p in st.session_state.favorites]:
|
234 |
st.session_state.favorites.append(pet)
|
235 |
st.success(f"Added {pet['name']} to favorites!")
|
236 |
st.rerun()
|
237 |
else:
|
238 |
+
if st.button("Remove from Favorites", key=f"unfav_{context}_{pet['id']}"):
|
239 |
st.session_state.favorites = [p for p in st.session_state.favorites if p['id'] != pet['id']]
|
240 |
st.success(f"Removed {pet['name']} from favorites!")
|
241 |
st.rerun()
|