diff --git a/pages/NewsletterSignup.py b/pages/NewsletterSignup.py index 7606b3f..3be3d00 100644 --- a/pages/NewsletterSignup.py +++ b/pages/NewsletterSignup.py @@ -1,5 +1,6 @@ import streamlit as st import re +from datetime import datetime def newsletter_signup_form(): """Displays the newsletter signup form and handles submission.""" @@ -30,6 +31,43 @@ def newsletter_signup_form(): .newsletter-card:hover { box-shadow: 0 4px 8px rgba(0,0,0,0.2); } + .tag { + display: inline-block; + background-color: #4CAF50; + color: white; + padding: 0.25rem 0.75rem; + border-radius: 15px; + font-size: 0.8rem; + margin: 0.25rem; + } + .stats-box { + background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); + color: white; + padding: 1.5rem; + border-radius: 10px; + text-align: center; + margin: 1rem 0; + } + .stats-number { + font-size: 2.5rem; + font-weight: bold; + } + .share-buttons { + display: flex; + gap: 0.5rem; + margin-top: 1rem; + } + .share-btn { + padding: 0.5rem 1rem; + border-radius: 5px; + text-decoration: none; + color: white; + font-size: 0.9rem; + transition: opacity 0.3s; + } + .share-btn:hover { + opacity: 0.8; + } """, unsafe_allow_html=True) @@ -38,68 +76,379 @@ def newsletter_signup_form(): st.header("💌 Subscribe to Our Weekly Newsletter") st.write("Get the latest wellness tips, mental health news, and exclusive content delivered straight to your inbox!") + # Subscriber Statistics + st.markdown(""" +
We respect your privacy and will never share your email. You can unsubscribe at any time.
", unsafe_allow_html=True) + + st.markdown("", unsafe_allow_html=True) + + +def subscription_management(): + """Shows subscription management options for existing subscribers.""" + st.markdown("", unsafe_allow_html=True) + + # Show unsubscribe confirmation + if st.session_state.get('show_unsubscribe', False): + with st.expander("⚠️ Unsubscribe Confirmation", expanded=True): + st.warning("Are you sure you want to unsubscribe? You'll miss out on valuable content!") + + col1, col2, col3 = st.columns([1, 1, 2]) + with col1: + if st.button("Yes, Unsubscribe"): + # Clear subscription data + st.session_state.subscribed = False + st.session_state.show_unsubscribe = False + for key in ['subscriber_name', 'subscriber_email', 'subscription_date', 'preferences', 'frequency']: + if key in st.session_state: + del st.session_state[key] + st.success("You've been unsubscribed. We're sorry to see you go!") + st.rerun() + + with col2: + if st.button("No, Keep Subscription"): + st.session_state.show_unsubscribe = False + st.rerun() + + # Show preference update form + if st.session_state.get('update_preferences', False): + st.markdown("---") + st.subheader("📝 Update Your Preferences") + + with st.form("update_preferences_form"): + st.markdown("### Topics") + col1, col2 = st.columns(2) + + current_prefs = st.session_state.get('preferences', {}) + + with col1: + mental_health = st.checkbox("Mental Health Tips", value=current_prefs.get("Mental Health Tips", True)) + wellness = st.checkbox("Wellness & Lifestyle", value=current_prefs.get("Wellness & Lifestyle", True)) + mindfulness = st.checkbox("Mindfulness Practices", value=current_prefs.get("Mindfulness Practices", True)) + + with col2: + nutrition = st.checkbox("Nutrition & Diet", value=current_prefs.get("Nutrition & Diet", False)) + exercise = st.checkbox("Exercise & Fitness", value=current_prefs.get("Exercise & Fitness", False)) + sleep = st.checkbox("Sleep & Rest", value=current_prefs.get("Sleep & Rest", False)) + + st.markdown("### Frequency") + frequency = st.radio( + "How often would you like to receive our newsletter?", + options=["Weekly (Recommended)", "Bi-weekly", "Monthly"], + index=["Weekly (Recommended)", "Bi-weekly", "Monthly"].index(st.session_state.get('frequency', 'Weekly (Recommended)')) + ) + + col1, col2 = st.columns(2) + with col1: + if st.form_submit_button("💾 Save Changes", use_container_width=True): + st.session_state.preferences = { + "Mental Health Tips": mental_health, + "Wellness & Lifestyle": wellness, + "Mindfulness Practices": mindfulness, + "Nutrition & Diet": nutrition, + "Exercise & Fitness": exercise, + "Sleep & Rest": sleep + } + st.session_state.frequency = frequency + st.session_state.update_preferences = False + st.success("✅ Preferences updated successfully!") + st.rerun() + + with col2: + if st.form_submit_button("❌ Cancel", use_container_width=True): + st.session_state.update_preferences = False + st.rerun() + def show(): """Renders the Newsletter Signup page.""" st.title("Newsletter Signup") - # Check if the user has already subscribed in this session + # Initialize session state if 'subscribed' not in st.session_state: st.session_state.subscribed = False + # Show appropriate content based on subscription status if st.session_state.subscribed: - st.success("You are already subscribed! Thank you for being a part of our community.") - st.markdown("---") - st.page_link("app.py", label="Back to Home", icon="🏠") + subscription_management() else: newsletter_signup_form() st.markdown("---") - st.subheader("📖 Past Newsletters") + + # Search and Filter Section + st.subheader("📖 Past Newsletters Archive") + + col1, col2, col3 = st.columns([2, 1, 1]) + with col1: + search_query = st.text_input("🔍 Search newsletters", placeholder="Search by title or content...", label_visibility="collapsed") + with col2: + category_filter = st.selectbox("Category", ["All", "Mental Health", "Wellness", "Mindfulness", "Nutrition", "Sleep"]) + with col3: + sort_by = st.selectbox("Sort by", ["Newest First", "Oldest First", "Most Popular"]) past_newsletters = [ { "title": "Mindful Mondays: The Power of Breath", "date": "October 6, 2025", - "summary": "This week, we explore the power of mindful breathing and how it can help you stay calm and centered throughout the day. We also share a simple breathing exercise that you can do anywhere, anytime." + "category": "Mindfulness", + "summary": "This week, we explore the power of mindful breathing and how it can help you stay calm and centered throughout the day. We also share a simple breathing exercise that you can do anywhere, anytime.", + "content": "Breathing is something we do unconsciously, but when we bring awareness to our breath, it becomes a powerful tool for managing stress and anxiety. In this newsletter, we dive deep into breathing techniques including box breathing, 4-7-8 breathing, and alternate nostril breathing. Each technique serves different purposes and can be used in various situations throughout your day.", + "tags": ["Breathing", "Stress Relief", "Mindfulness"], + "read_time": "5 min read", + "views": 1248 }, { "title": "Wellness Wednesdays: The Importance of Sleep", "date": "September 29, 2025", - "summary": "In this issue, we dive into the science of sleep and why it's so crucial for your mental and physical health. We also provide some tips for getting a better night's sleep." + "category": "Sleep", + "summary": "In this issue, we dive into the science of sleep and why it's so crucial for your mental and physical health. We also provide some tips for getting a better night's sleep.", + "content": "Sleep is not just rest - it's an active process where your body repairs itself, consolidates memories, and regulates hormones. We explore the sleep cycles, the importance of REM sleep, and how chronic sleep deprivation affects your mental health. You'll learn about sleep hygiene, optimal bedroom conditions, and natural ways to improve sleep quality without medication.", + "tags": ["Sleep", "Health", "Recovery"], + "read_time": "7 min read", + "views": 2156 }, { "title": "Feel-Good Fridays: The Benefits of Gratitude", "date": "September 22, 2025", - "summary": "This week, we focus on the power of gratitude and how it can improve your mood and overall well-being. We also share a simple gratitude journaling exercise." + "category": "Mental Health", + "summary": "This week, we focus on the power of gratitude and how it can improve your mood and overall well-being. We also share a simple gratitude journaling exercise.", + "content": "Scientific research shows that practicing gratitude can rewire your brain for happiness. We explore the neuroscience behind gratitude, share compelling research studies, and provide practical exercises you can start today. Learn about the 3 Good Things exercise, gratitude letters, and how to build a sustainable gratitude practice that fits your lifestyle.", + "tags": ["Gratitude", "Happiness", "Mental Health"], + "read_time": "6 min read", + "views": 1876 + }, + { + "title": "Nutrition Notes: Foods That Boost Your Mood", + "date": "September 15, 2025", + "category": "Nutrition", + "summary": "Discover the surprising connection between what you eat and how you feel. We explore mood-boosting foods and the gut-brain connection.", + "content": "Your gut produces 90% of your body's serotonin! Learn about the gut-brain axis and how the foods you eat directly impact your mental health. We cover omega-3 fatty acids, probiotics, complex carbohydrates, and foods rich in B vitamins. Plus, get easy recipes for mood-boosting smoothies and snacks.", + "tags": ["Nutrition", "Mental Health", "Recipes"], + "read_time": "8 min read", + "views": 1543 + }, + { + "title": "Movement Matters: Exercise for Mental Clarity", + "date": "September 8, 2025", + "category": "Wellness", + "summary": "Learn how different types of exercise affect your mental health and cognitive function. From yoga to HIIT, find what works for you.", + "content": "Exercise isn't just for physical health - it's a powerful tool for mental wellness. We break down the mental health benefits of different exercise types: yoga for stress reduction, cardio for mood elevation, strength training for confidence, and walking for creativity. Includes a 7-day movement challenge!", + "tags": ["Exercise", "Mental Health", "Fitness"], + "read_time": "6 min read", + "views": 1392 + }, + { + "title": "Stress Less: Managing Modern Life Pressures", + "date": "September 1, 2025", + "category": "Mental Health", + "summary": "Practical strategies for managing stress in our fast-paced world. Learn techniques that actually work backed by science.", + "content": "Stress is inevitable, but chronic stress is harmful. We explore the physiology of stress, how to recognize your stress triggers, and evidence-based techniques for stress management including progressive muscle relaxation, time-blocking, and setting healthy boundaries. Real-life case studies included.", + "tags": ["Stress", "Coping Skills", "Mental Health"], + "read_time": "9 min read", + "views": 2401 } ] - cols = st.columns(2) - for i, newsletter in enumerate(past_newsletters): - with cols[i % 2]: - st.markdown(f""" - - """, unsafe_allow_html=True) + # Filter newsletters + filtered_newsletters = past_newsletters + + if search_query: + filtered_newsletters = [ + n for n in filtered_newsletters + if search_query.lower() in n['title'].lower() + or search_query.lower() in n['summary'].lower() + or search_query.lower() in n['content'].lower() + ] + + if category_filter != "All": + filtered_newsletters = [n for n in filtered_newsletters if n['category'] == category_filter] + + # Sort newsletters + if sort_by == "Newest First": + filtered_newsletters.sort(key=lambda x: x['date'], reverse=True) + elif sort_by == "Oldest First": + filtered_newsletters.sort(key=lambda x: x['date']) + elif sort_by == "Most Popular": + filtered_newsletters.sort(key=lambda x: x['views'], reverse=True) + + # Show results count + st.markdown(f"*Showing {len(filtered_newsletters)} of {len(past_newsletters)} newsletters*") + + if not filtered_newsletters: + st.info("No newsletters found matching your search criteria. Try different keywords!") + else: + cols = st.columns(2) + for i, newsletter in enumerate(filtered_newsletters): + with cols[i % 2]: + with st.container(): + st.markdown(f""" + ", unsafe_allow_html=True) + + # Footer with helpful links + st.markdown("---") + st.markdown(""" ++ Contact Us • + Privacy Policy • + FAQ +
++ © 2025 Mental Health Newsletter. All rights reserved. +
+