File size: 4,938 Bytes
6dc0e95
c219286
b8c0afd
 
 
c219286
1f78d79
 
 
6dc0e95
 
 
 
 
 
 
 
 
 
1f78d79
 
6dc0e95
 
 
 
 
 
 
 
 
1f78d79
6dc0e95
 
 
1f78d79
 
 
 
 
 
 
 
cef3ca5
1f78d79
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cef3ca5
 
 
 
 
 
 
 
1f78d79
cef3ca5
 
 
 
1f78d79
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cef3ca5
 
6dc0e95
1f78d79
 
 
 
 
 
6dc0e95
1f78d79
 
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
import os
import streamlit as st
from dotenv import load_dotenv

load_dotenv()

# Constants
data_folder = "data"
preview_folder = "Preview"

# Extracting text from .txt files
def get_text_files_content(folder):
    text = ""
    for filename in os.listdir(folder):
        if filename.endswith('.txt'):
            with open(os.path.join(folder, filename), 'r', encoding='utf-8') as file:
                text += file.read() + "\n"
    return text

def notes_page():
    st.header("CSS Edge - Notes Viewer :books:")

    subjects = [
        "A Trumped World", "Agri Tax in Punjab", "Assad's Fall in Syria", "Elusive National Unity", "Europe and Trump 2.0",
        "Going Down with Democracy", "Indonesia's Pancasila Philosophy", "Pakistan in Choppy Waters",
        "Pakistan's Semiconductor Ambitions", "Preserving Pakistan's Cultural Heritage", "Tackling Informal Economy",
        "Technical Education in Pakistan", "The Case for Solidarity Levies", "The Decline of the Sole Superpower",
        "The Power of Big Oil", "Trump 2.0 and Pakistan's Emerging Foreign Policy", "Trump and the World 2.0",
        "Trump vs BRICS", "US-China Trade War", "War on Humanity", "Women's Suppression in Afghanistan"
    ]

    subject_folders = {subject: os.path.join(data_folder, subject.replace(' ', '_')) for subject in subjects}
    preview_folders = {subject: os.path.join(preview_folder, subject.replace(' ', '_')) for subject in subjects}

    if "completed_subjects" not in st.session_state:
        st.session_state.completed_subjects = []

    if "current_subject_index" not in st.session_state:
        st.session_state.current_subject_index = 0

    if "grading_enabled" not in st.session_state:
        st.session_state.grading_enabled = False

    # Separate completed and unread subjects
    unread_subjects = [sub for sub in subjects if sub not in st.session_state.completed_subjects]
    completed_subjects = st.session_state.completed_subjects

    # Dropdown to filter subjects
    filter_option = st.sidebar.selectbox("Filter Notes:", ["All", "Unread", "Read"])

    if filter_option == "Unread":
        displayed_subjects = unread_subjects
    elif filter_option == "Read":
        displayed_subjects = completed_subjects
    else:
        displayed_subjects = subjects

    # Dropdown to directly jump to specific unread note
    if filter_option == "Unread" and unread_subjects:
        selected_unread_subject = st.sidebar.selectbox("Go to Unread Note:", unread_subjects)
        st.session_state.current_subject_index = subjects.index(selected_unread_subject)

    # Sidebar list of subjects
    st.sidebar.subheader("All Subjects")
    for i, subject in enumerate(displayed_subjects):
        status = "✓" if subject in st.session_state.completed_subjects else ""
        st.sidebar.text(f"{i + 1}. {subject} {status}")

    # Get the current subject
    selected_subject = subjects[st.session_state.current_subject_index]
    st.sidebar.subheader("Current Subject:")
    st.sidebar.text(selected_subject)

    # Display preview content
    preview_folder_path = preview_folders[selected_subject]
    if os.path.exists(preview_folder_path):
        preview_text = get_text_files_content(preview_folder_path)
        st.subheader("Preview of Notes")
        st.text_area("Preview Content:", preview_text, height=300, disabled=True)
    else:
        st.error(f"No preview available for {selected_subject}.")

    # Display full notes
    subject_folder_path = subject_folders[selected_subject]
    if os.path.exists(subject_folder_path):
        raw_text = get_text_files_content(subject_folder_path)
        if raw_text:
            st.subheader("Notes")
            st.text_area("Notes Content:", raw_text, height=500, disabled=True)

            # Mark as completed button
            if selected_subject not in st.session_state.completed_subjects:
                if st.button(f"Mark '{selected_subject}' as Read"):
                    st.session_state.completed_subjects.append(selected_subject)
                    st.success(f"Marked '{selected_subject}' as read!")

            # Check if all notes are completed
            if len(st.session_state.completed_subjects) == len(subjects):
                st.session_state.grading_enabled = True
                st.sidebar.success("All subjects completed. You can now proceed to the Grading Tool.")
                st.markdown("[Proceed to Grading Tool](https://chatgpt.com/)")

            # Next subject button
            if st.session_state.current_subject_index < len(subjects) - 1:
                if st.button("Go to Next Note"):
                    st.session_state.current_subject_index += 1
    else:
        st.error(f"No data available for {selected_subject}.")

def main():
    st.sidebar.title("Navigation")
    page = st.sidebar.radio("Select a Page:", ["Notes"])

    if page == "Notes":
        notes_page()

if __name__ == "__main__":
    main()