CCockrum commited on
Commit
85285ba
·
verified ·
1 Parent(s): b0311af

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -14
app.py CHANGED
@@ -284,6 +284,7 @@ def get_compatibility_message(pet):
284
  return messages
285
 
286
  # Function to display pet details page
 
287
  def display_pet_details(pet_id, context="search"):
288
  pet = get_pet_details(pet_id)
289
  if not pet:
@@ -292,11 +293,11 @@ def display_pet_details(pet_id, context="search"):
292
 
293
  # Back button
294
  if st.button("← Back to Search Results", key=f"back_{context}_{pet_id}"):
295
- #if st.session_state.selected_pet is not None:
296
- st.session_state.selected_pet = None
297
- st.rerun() # Force immediate rerun
298
- # Pet name and status
299
- st.markdown(f"<h1 class='main-header'>{pet['name']}</h1>", unsafe_allow_html=True)
300
 
301
  status_color = "#c8e6c9" if pet['status'] == 'adoptable' else "#ffcdd2"
302
  st.markdown(f"<div style='text-align: center;'><span class='tag' style='background-color: {status_color}; font-size: 1rem;'>{pet['status'].title()}</span></div>", unsafe_allow_html=True)
@@ -328,15 +329,15 @@ def display_pet_details(pet_id, context="search"):
328
  f"**Age:** {pet['age']}",
329
  f"**Gender:** {pet['gender']}",
330
  f"**Size:** {pet['size']}"
331
- ]
332
 
333
- # Fix the colors line as well, to be safe
334
- colors = [c for c in [pet['colors']['primary'], pet['colors']['secondary'], pet['colors']['tertiary']] if c]
335
- if colors:
336
- details.append(f"**Colors:** {', '.join(colors)}")
337
 
338
- for detail in details:
339
- st.markdown(detail)
340
 
341
  with col2:
342
  st.markdown("### Compatibility")
@@ -375,12 +376,12 @@ def display_pet_details(pet_id, context="search"):
375
  # Add to favorites
376
  is_favorite = pet['id'] in [p['id'] for p in st.session_state.favorites]
377
  if not is_favorite:
378
- if st.button("Add to Favorites"):
379
  st.session_state.favorites.append(pet)
380
  st.success(f"Added {pet['name']} to favorites!")
381
  st.rerun()
382
  else:
383
- if st.button("Remove from Favorites"):
384
  st.session_state.favorites = [p for p in st.session_state.favorites if p['id'] != pet['id']]
385
  st.success(f"Removed {pet['name']} from favorites!")
386
  st.rerun()
 
284
  return messages
285
 
286
  # Function to display pet details page
287
+ # The fix is in the display_pet_details function
288
  def display_pet_details(pet_id, context="search"):
289
  pet = get_pet_details(pet_id)
290
  if not pet:
 
293
 
294
  # Back button
295
  if st.button("← Back to Search Results", key=f"back_{context}_{pet_id}"):
296
+ st.session_state.selected_pet = None
297
+ st.rerun() # Force immediate rerun
298
+
299
+ # Pet name and status
300
+ st.markdown(f"<h1 class='main-header'>{pet['name']}</h1>", unsafe_allow_html=True)
301
 
302
  status_color = "#c8e6c9" if pet['status'] == 'adoptable' else "#ffcdd2"
303
  st.markdown(f"<div style='text-align: center;'><span class='tag' style='background-color: {status_color}; font-size: 1rem;'>{pet['status'].title()}</span></div>", unsafe_allow_html=True)
 
329
  f"**Age:** {pet['age']}",
330
  f"**Gender:** {pet['gender']}",
331
  f"**Size:** {pet['size']}"
332
+ ]
333
 
334
+ # Fix the colors line as well, to be safe
335
+ colors = [c for c in [pet['colors']['primary'], pet['colors']['secondary'], pet['colors']['tertiary']] if c]
336
+ if colors:
337
+ details.append(f"**Colors:** {', '.join(colors)}")
338
 
339
+ for detail in details:
340
+ st.markdown(detail)
341
 
342
  with col2:
343
  st.markdown("### Compatibility")
 
376
  # Add to favorites
377
  is_favorite = pet['id'] in [p['id'] for p in st.session_state.favorites]
378
  if not is_favorite:
379
+ if st.button("Add to Favorites", key=f"add_fav_{context}_{pet_id}"):
380
  st.session_state.favorites.append(pet)
381
  st.success(f"Added {pet['name']} to favorites!")
382
  st.rerun()
383
  else:
384
+ if st.button("Remove from Favorites", key=f"rem_fav_{context}_{pet_id}"):
385
  st.session_state.favorites = [p for p in st.session_state.favorites if p['id'] != pet['id']]
386
  st.success(f"Removed {pet['name']} from favorites!")
387
  st.rerun()