File size: 2,743 Bytes
82a36a6
 
a962ffe
897c1d2
 
0759822
b7a713a
0759822
29a4bc9
90cb4f4
88f694a
fa1e621
9a6b7dc
897c1d2
e3f0784
00eef23
82a36a6
9a6b7dc
 
 
 
e4a1a2b
 
9a6b7dc
 
 
 
0759822
 
 
 
29a4bc9
 
4f7c053
 
46dae9a
 
29a4bc9
 
9a6b7dc
 
 
 
90cb4f4
c7dea7e
9a6b7dc
 
29a4bc9
 
897c1d2
9a6b7dc
 
29a4bc9
0759822
9a6b7dc
0759822
 
 
 
 
 
 
 
64656b5
0759822
29a4bc9
0759822
 
 
 
 
9a6b7dc
 
 
 
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
from utils.loaders import load_data
from db.crud import read
import streamlit as st
import os
from dotenv import load_dotenv
from views.intro_screen import welcome_screen
from views.questions_screen import questions_screen
from views.continue_survey import continue_survey_screen
from views.ui_helpers import exit_screen, display_completion_message
from css.layout import custom_css

st.set_page_config(layout="wide")

load_dotenv()
VALIDATION_CODE = os.getenv("VALIDATION_CODE")


def initialization():
    """Initialize session state variables."""
    if "current_index" not in st.session_state:
        st.session_state.current_index = 0
    if "username" not in st.session_state:
        st.session_state.username = None
    if "responses" not in st.session_state:
        st.session_state.responses = []
    if "completed" not in st.session_state:
        st.session_state.completed = False
    if "show_questions" not in st.session_state:
        st.session_state.show_questions = False
    if "survey_continued" not in st.session_state:
        st.session_state.survey_continued = None
    # if "start_new_survey" not in st.session_state:
    #     st.session_state.start_new_survey = False
    if 'ratings' not in st.session_state:
        st.session_state.ratings = {}
    if 'previous_ratings' not in st.session_state:
        st.session_state.previous_ratings = {}
    if 'screen' not in st.session_state:
        st.session_state.screen = 'welcome'


def ui():
    """Main function to control the survey flow."""
    custom_css()
    data = load_data()
    initialization()

    if st.session_state.completed: \
            # and not st.session_state.start_new_survey:
        exit_screen()
        return

    if st.session_state.username is None and st.session_state.screen == 'welcome':
        welcome_screen()
    else:
        # Check if user progress exists in Firebase
        saved_state = read(st.session_state.username)
        if saved_state:
            # If there's saved progress and the survey has not been continued, show continue screen
            if "survey_continued" not in st.session_state or not st.session_state.survey_continued:
                continue_survey_screen(data)
            else:
                if st.session_state.current_index >= len(data):
                    # If all questions have been answered, show the exit screen
                    print("survey completed")
                    display_completion_message()
                # Otherwise, show questions from where they left off
                questions_screen(data)
        else:
            # If no saved progress (new user), start with the questions screen
            questions_screen(data)


if __name__ == "__main__":
    ui()