Update app.py
Browse files
app.py
CHANGED
|
@@ -42,84 +42,84 @@ def load_note(subject, unit, note):
|
|
| 42 |
st.set_page_config(
|
| 43 |
page_title="Beautiful Notes App",
|
| 44 |
page_icon="๐",
|
| 45 |
-
layout="wide",
|
| 46 |
initial_sidebar_state="expanded",
|
| 47 |
)
|
| 48 |
|
| 49 |
st.title("๐ Beautiful Notes App")
|
| 50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
# Sidebar for navigation
|
| 52 |
with st.sidebar:
|
| 53 |
st.header("Navigation")
|
| 54 |
subjects = get_subjects()
|
| 55 |
-
selected_subject = st.selectbox("Select Subject", subjects)
|
|
|
|
| 56 |
|
| 57 |
-
if selected_subject:
|
| 58 |
-
units = get_units(selected_subject)
|
| 59 |
if units:
|
| 60 |
-
selected_unit = st.selectbox("Select Unit", units)
|
| 61 |
-
|
| 62 |
-
|
|
|
|
| 63 |
if notes:
|
| 64 |
-
selected_note = st.selectbox("Select Note", notes)
|
|
|
|
| 65 |
else:
|
| 66 |
st.info("No notes found in this unit.")
|
| 67 |
-
selected_note = None
|
| 68 |
else:
|
| 69 |
st.info("No units found in this subject.")
|
| 70 |
-
selected_note = None
|
| 71 |
else:
|
| 72 |
st.info("No units found in this subject.")
|
| 73 |
-
selected_note = None
|
| 74 |
else:
|
| 75 |
st.info("No subjects found in the data directory.")
|
| 76 |
-
selected_note = None
|
| 77 |
|
| 78 |
# Main area to display notes
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
if
|
| 83 |
-
st.
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
st.
|
| 88 |
-
|
| 89 |
-
st.
|
| 90 |
-
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
| 92 |
st.markdown(
|
| 93 |
"""
|
| 94 |
<style>
|
| 95 |
-
/*
|
| 96 |
-
.streamlit-expander {
|
| 97 |
-
border: 1px solid #ccc;
|
| 98 |
-
border-radius: 5px;
|
| 99 |
-
margin-bottom: 10px;
|
| 100 |
-
}
|
| 101 |
-
.streamlit-expander-header {
|
| 102 |
-
font-weight: bold;
|
| 103 |
-
padding: 10px;
|
| 104 |
-
}
|
| 105 |
-
.streamlit-expander-content {
|
| 106 |
-
padding: 10px;
|
| 107 |
-
}
|
| 108 |
body {
|
| 109 |
font-family: sans-serif;
|
| 110 |
color: #333;
|
| 111 |
background-color: #f4f4f4;
|
|
|
|
| 112 |
}
|
| 113 |
.stApp {
|
| 114 |
-
max-width:
|
| 115 |
-
|
| 116 |
-
padding: 20px;
|
| 117 |
-
background-color: white;
|
| 118 |
-
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
| 119 |
-
border-radius: 10px;
|
| 120 |
}
|
| 121 |
h1 {
|
| 122 |
color: #007bff;
|
|
|
|
| 123 |
}
|
| 124 |
h2, h3, h4, h5, h6 {
|
| 125 |
color: #0056b3;
|
|
@@ -127,6 +127,57 @@ st.markdown(
|
|
| 127 |
.st-bf { /* Styling for selectbox labels */
|
| 128 |
font-weight: bold;
|
| 129 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
</style>
|
| 131 |
""",
|
| 132 |
unsafe_allow_html=True,
|
|
|
|
| 42 |
st.set_page_config(
|
| 43 |
page_title="Beautiful Notes App",
|
| 44 |
page_icon="๐",
|
| 45 |
+
layout="wide", # Keep wide for potential wider content, adjust with CSS
|
| 46 |
initial_sidebar_state="expanded",
|
| 47 |
)
|
| 48 |
|
| 49 |
st.title("๐ Beautiful Notes App")
|
| 50 |
|
| 51 |
+
# --- State Management ---
|
| 52 |
+
if 'selected_subject' not in st.session_state:
|
| 53 |
+
st.session_state['selected_subject'] = None
|
| 54 |
+
if 'selected_unit' not in st.session_state:
|
| 55 |
+
st.session_state['selected_unit'] = None
|
| 56 |
+
if 'selected_note' not in st.session_state:
|
| 57 |
+
st.session_state['selected_note'] = None
|
| 58 |
+
|
| 59 |
# Sidebar for navigation
|
| 60 |
with st.sidebar:
|
| 61 |
st.header("Navigation")
|
| 62 |
subjects = get_subjects()
|
| 63 |
+
selected_subject = st.selectbox("Select Subject", subjects, key="subject_selectbox")
|
| 64 |
+
st.session_state['selected_subject'] = selected_subject
|
| 65 |
|
| 66 |
+
if st.session_state['selected_subject']:
|
| 67 |
+
units = get_units(st.session_state['selected_subject'])
|
| 68 |
if units:
|
| 69 |
+
selected_unit = st.selectbox("Select Unit", units, key="unit_selectbox")
|
| 70 |
+
st.session_state['selected_unit'] = selected_unit
|
| 71 |
+
if st.session_state['selected_unit']:
|
| 72 |
+
notes = get_notes(st.session_state['selected_subject'], st.session_state['selected_unit'])
|
| 73 |
if notes:
|
| 74 |
+
selected_note = st.selectbox("Select Note", notes, key="note_selectbox")
|
| 75 |
+
st.session_state['selected_note'] = selected_note
|
| 76 |
else:
|
| 77 |
st.info("No notes found in this unit.")
|
| 78 |
+
st.session_state['selected_note'] = None
|
| 79 |
else:
|
| 80 |
st.info("No units found in this subject.")
|
| 81 |
+
st.session_state['selected_note'] = None
|
| 82 |
else:
|
| 83 |
st.info("No units found in this subject.")
|
| 84 |
+
st.session_state['selected_note'] = None
|
| 85 |
else:
|
| 86 |
st.info("No subjects found in the data directory.")
|
| 87 |
+
st.session_state['selected_note'] = None
|
| 88 |
|
| 89 |
# Main area to display notes
|
| 90 |
+
col1, col2 = st.columns([1, 3]) # Adjust column widths as needed for mobile
|
| 91 |
+
|
| 92 |
+
with col2:
|
| 93 |
+
if st.session_state['selected_subject'] and st.session_state['selected_unit'] and st.session_state['selected_note']:
|
| 94 |
+
st.header(f"{st.session_state['selected_subject']} / {st.session_state['selected_unit']} / {st.session_state['selected_note'][:-3]}") # Remove .md extension
|
| 95 |
+
note_content = load_note(st.session_state['selected_subject'], st.session_state['selected_unit'], st.session_state['selected_note'])
|
| 96 |
+
if note_content:
|
| 97 |
+
st.markdown(note_content, unsafe_allow_html=True)
|
| 98 |
+
elif st.session_state['selected_subject'] and st.session_state['selected_unit']:
|
| 99 |
+
st.info("Select a note from the sidebar to view it.")
|
| 100 |
+
elif st.session_state['selected_subject']:
|
| 101 |
+
st.info("Select a unit from the sidebar to view notes.")
|
| 102 |
+
else:
|
| 103 |
+
st.info("Select a subject from the sidebar to start exploring your notes.")
|
| 104 |
+
|
| 105 |
+
# --- Styling for Mobile ---
|
| 106 |
st.markdown(
|
| 107 |
"""
|
| 108 |
<style>
|
| 109 |
+
/* General Styles */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
body {
|
| 111 |
font-family: sans-serif;
|
| 112 |
color: #333;
|
| 113 |
background-color: #f4f4f4;
|
| 114 |
+
margin: 0; /* Remove default body margin */
|
| 115 |
}
|
| 116 |
.stApp {
|
| 117 |
+
max-width: 100%; /* Occupy full width */
|
| 118 |
+
padding: 10px; /* Reduced padding for smaller screens */
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
}
|
| 120 |
h1 {
|
| 121 |
color: #007bff;
|
| 122 |
+
text-align: center; /* Center the title on mobile */
|
| 123 |
}
|
| 124 |
h2, h3, h4, h5, h6 {
|
| 125 |
color: #0056b3;
|
|
|
|
| 127 |
.st-bf { /* Styling for selectbox labels */
|
| 128 |
font-weight: bold;
|
| 129 |
}
|
| 130 |
+
.streamlit-expander {
|
| 131 |
+
border: 1px solid #ccc;
|
| 132 |
+
border-radius: 5px;
|
| 133 |
+
margin-bottom: 10px;
|
| 134 |
+
}
|
| 135 |
+
.streamlit-expander-header {
|
| 136 |
+
font-weight: bold;
|
| 137 |
+
padding: 8px;
|
| 138 |
+
}
|
| 139 |
+
.streamlit-expander-content {
|
| 140 |
+
padding: 8px;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
/* Sidebar Styles */
|
| 144 |
+
.stSidebar {
|
| 145 |
+
padding-top: 1rem;
|
| 146 |
+
}
|
| 147 |
+
.stSidebar > div[data-testid="stVerticalBlock"] {
|
| 148 |
+
padding: 20px; /* Add padding to sidebar content */
|
| 149 |
+
overflow: auto; /* Enable scrolling if content overflows */
|
| 150 |
+
max-height: calc(100vh - 50px); /* Limit height and enable scrolling */
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
/* Main Content Styles */
|
| 154 |
+
.block-container {
|
| 155 |
+
padding-top: 1rem !important;
|
| 156 |
+
padding-bottom: 1rem !important;
|
| 157 |
+
padding-left: 1rem !important;
|
| 158 |
+
padding-right: 1rem !important;
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
/* Mobile Specific Styles */
|
| 162 |
+
@media (max-width: 768px) {
|
| 163 |
+
.stApp {
|
| 164 |
+
padding: 5px; /* Further reduce padding on very small screens */
|
| 165 |
+
}
|
| 166 |
+
h1 {
|
| 167 |
+
font-size: 24px; /* Smaller title on mobile */
|
| 168 |
+
}
|
| 169 |
+
.st-bf {
|
| 170 |
+
font-size: 14px; /* Smaller label font */
|
| 171 |
+
}
|
| 172 |
+
/* Adjust selectbox size and padding */
|
| 173 |
+
div[data-baseweb="select"] > div {
|
| 174 |
+
padding-top: 6px;
|
| 175 |
+
padding-bottom: 6px;
|
| 176 |
+
}
|
| 177 |
+
.stMarkdown {
|
| 178 |
+
font-size: 16px; /* More readable font size for content */
|
| 179 |
+
}
|
| 180 |
+
}
|
| 181 |
</style>
|
| 182 |
""",
|
| 183 |
unsafe_allow_html=True,
|