-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
119 lines (100 loc) · 3.9 KB
/
main.py
File metadata and controls
119 lines (100 loc) · 3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import streamlit as st
from pathlib import Path
from db.models import init_db, load_profile_from_db
from db.database import get_connection
from services.mood_service import check_mood_logged_today
from ui.layout import (
render_profile_page,
render_intro_page,
render_home_page,
render_dashboard
)
# ________________________________________
# Configuration de la page
# _______________________________________
st.set_page_config(
page_title="Help-Desk - Compagnon du quotidien",
page_icon="💙",
layout="wide",
initial_sidebar_state="collapsed"
)
# ________________________________________
# Initialisation de la base de données
# ________________________________________
# Créer le dossier data s'il n'existe pas
Path("data").mkdir(exist_ok=True)
# Initialiser les tables____________________
init_db()
# Connexion à la base______________________
if "conn" not in st.session_state:
st.session_state.conn = get_connection()
# ________________________________________
# Initialisation du session_state
# _______________________________________
defaults = {
"profile_created": False,
"profile": None,
"intro_done": False,
"mood_logged_today": False,
"selected_day": None
}
for key, value in defaults.items():
if key not in st.session_state:
st.session_state[key] = value
# _______________________________________
# Charger le profil existant depuis la DB
# _______________________________________
if not st.session_state.profile_created:
profile = load_profile_from_db()
if profile:
st.session_state.profile = profile
st.session_state.profile_created = True
st.session_state.intro_done = True # Si le profil existe, intro est déjà passée__________________
# _____________________________________________________
# Vérifier si l'humeur a été enregistrée aujourd'hui
# _____________________________________________________
if st.session_state.profile_created and not st.session_state.mood_logged_today:
if check_mood_logged_today():
st.session_state.mood_logged_today = True
# _______________________________________
# Chargement du thème CSS (optionnel)
# ________________________________________
css_file = Path("assets/theme.css")
if css_file.exists():
with open(css_file) as f:
st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
# ________________________________________
# Sidebar avec navigation et infos
# _______________________________________
with st.sidebar:
st.title("💙 Help-Desk")
st.markdown("---")
if st.session_state.profile_created and st.session_state.profile:
st.markdown(f"**Connecté en tant que :** \n{st.session_state.profile['prenom']}")
if st.session_state.profile.get('tags'):
st.markdown("**Tags :**")
for tag in st.session_state.profile['tags']:
st.markdown(f"- {tag}")
st.markdown("---")
# Bouton pour recommencer le parcours____________________________
if st.button("🔄 Recommencer"):
st.session_state.mood_logged_today = False
st.rerun()
st.markdown("---")
st.caption("💡 Ton compagnon du quotidien")
st.caption("🔒 Tes données sont stockées localement et protégées")
# ________________________________________
# Navigation principale
# _______________________________________
if not st.session_state.profile_created or not st.session_state.profile:
# Étape 1 : Création du profil___________________________________
render_profile_page()
elif not st.session_state.intro_done:
# Étape 2 : Introduction________________________________________
render_intro_page()
elif not st.session_state.mood_logged_today:
# Étape 3 : Humeur du jour________________________________________
render_home_page()
else:
# Étape 4 : Dashboard principal___________________________________
render_dashboard()