diff --git a/src/api/endpoints.py b/src/api/endpoints.py
index 9a74d7f..b5985a6 100644
--- a/src/api/endpoints.py
+++ b/src/api/endpoints.py
@@ -25,10 +25,10 @@ async def get_calendar() -> JSONResponse:
JSONResponse: A JSON response containing the calendar data.
"""
- events: dict[str, str] = {}
+ events: list[dict[str, str]] = []
try:
- get_future_events_ical: tuple[
+ get_future_events_ical: list[
cshcalendar.CalendarInfo
] = await cshcalendar.get_future_events()
events = cshcalendar.format_events(get_future_events_ical)
@@ -36,7 +36,7 @@ async def get_calendar() -> JSONResponse:
logger.error(f"Error fetching calendar events: {e}")
return JSONResponse({"status": "error", "message": str(e)}, status_code=500)
- return JSONResponse(events)
+ return JSONResponse({"data": events})
@router.get("/announcement")
diff --git a/src/core/cshcalendar.py b/src/core/cshcalendar.py
index beedb0c..01b7c34 100644
--- a/src/core/cshcalendar.py
+++ b/src/core/cshcalendar.py
@@ -136,31 +136,7 @@ def repl(match: re.Match[str]) -> str:
return TIME_PATTERN.sub(repl, unformatted_string)
-
-def calendar_to_html(seg_header: str, seg_content: str) -> str:
- """
- Formats a header and content into the HTML for the calendar front end
-
- Args:
- seg_header (str): The header of the calendar segment
- seg_content (str): The content in the calendar segment
-
- Returns:
- str:
- """
-
- ret_string: str = (
- """
"""
- + seg_header
- + """
"""
- )
- ret_string += (
- "" + seg_content + "
"
- )
- return ret_string
-
-
-def format_events(events: tuple[CalendarInfo]) -> dict[str, str]:
+def format_events(events: list[CalendarInfo]) -> list[dict[str, str]]:
"""
Formats a parsed list of CalendarInfos, and returns the HTML required for front end
@@ -168,22 +144,19 @@ def format_events(events: tuple[CalendarInfo]) -> dict[str, str]:
events: The list of CalendarInfos to be formatted
Returns:
- dict: Returns a dictionary with the "data" key mapping to the HTML data.
+ list[dict[str, str]]: Returns a dictionary with the "data" key mapping to a list of dictionarys of each event.
"""
current_date: date = datetime.now(ZoneInfo(CALENDAR_TIMEZONE))
- final_events: str = "
"
if not events:
- final_events += BORDER_STRING
+ return {"data": [{"header": ":(", "content": "No Events on the Calendar"}]}
- final_events += calendar_to_html(":(", "No Events on the Calendar")
-
- final_events += BORDER_STRING
-
- return {"data": final_events}
+ formatted_list: list[dict[str, str]] = []
for event in events:
+ content_dict: dict[str, str] = {}
+
event_cur_happening: bool = event.date < current_date
if event_cur_happening:
formatted: str = (
@@ -191,14 +164,14 @@ def format_events(events: tuple[CalendarInfo]) -> dict[str, str]:
if event.location
else "Happening Now!"
)
- final_events += calendar_to_html(formatted, event.name)
+ content_dict["header"] = formatted
+ content_dict["content"] = str(event.name)
else:
- final_events += calendar_to_html(
- time_humanizer(current_date, event.date), event.name
- )
+ content_dict["header"] = time_humanizer(current_date, event.date)
+ content_dict["content"] = str(event.name)
- final_events += BORDER_STRING
- return {"data": final_events}
+ formatted_list.append(content_dict)
+ return formatted_list
async def rebuild_calendar() -> None:
@@ -261,7 +234,7 @@ async def get_future_events() -> list[CalendarInfo]:
custom object has name, date and the location
Returns:
- list: A list of CalendarInfo objects
+ list[CalendarInfo]: A list of CalendarInfo objects
"""
global \
diff --git a/src/static/css/style.css b/src/static/css/style.css
index 3ffbc71..f3f7066 100644
--- a/src/static/css/style.css
+++ b/src/static/css/style.css
@@ -165,16 +165,6 @@ body{
white-space: pre-line;
}
-.wikithoughts-page-name-header{
- color: var(--panel-header-text-color);
- font-family: 'Courier New', Courier, monospace;
- font-size: 20px;
- text-align: left;
- white-space: pre-line;
- display: block;
- font-style: italic;
-}
-
.wikithoughts-text-body{
color:var(--panel-body-text-color);
font-family: 'Courier New', Courier, monospace;
diff --git a/src/static/js/main.js b/src/static/js/main.js
index 98cb8a6..457cb72 100644
--- a/src/static/js/main.js
+++ b/src/static/js/main.js
@@ -71,6 +71,41 @@ function setNewPageTheme(newTheme) {
document.body.classList.toggle(newTheme);
}
+function createCalendarEvent(headerText, contentText) {
+ const container = document.createElement("div");
+ container.className = "calendar-event-container-lvl2";
+
+ const headerLabel = document.createElement("span");
+ headerLabel.className = "calendar-text-date";
+ headerLabel.textContent = headerText;
+ container.appendChild(headerLabel);
+
+ container.appendChild(document.createElement("br"));
+
+ const contentLabel = document.createElement("span");
+ contentLabel.className = "calendar-text";
+ contentLabel.textContent = contentText;
+ container.appendChild(contentLabel);
+
+ return container;
+}
+
+async function generateCalendar(calData) {
+
+ const calendar = document.getElementById('calendar');
+ calendar.replaceChildren();
+ calendar.appendChild(document.createElement("br"));
+
+ for (const event of calData) {
+ const newEvent = createCalendarEvent(event.header, event.content);
+ calendar.appendChild(newEvent);
+
+ const bracket = document.createElement("hr");
+ bracket.className = "calendar-border";
+ calendar.appendChild(bracket);
+ }
+}
+
async function longUpdate() {
const date = new Date();
const hour = date.getHours();
@@ -107,7 +142,7 @@ async function longUpdate() {
const res = await fetch('/api/calendar', { method: 'GET', mode: 'cors' });
const data = await res.json();
- $("#calendar").html(data.data);
+ await generateCalendar(data.data);
} catch (err) {
console.log(err);
}
@@ -121,7 +156,7 @@ async function mediumUpdate() {
]);
const wikiData = await wikiRes.json();
const announcementData = await announcementRes.json();
- $("#wikipageheader").text(wikiData.page)
+ $("#wikipageheader").text("csh/Wikithoughts - " + wikiData.page)
$("#wikipagetext").text(wikiData.content);
$("#announcement").text(announcementData.content.substring(0, 910));
$("#announcement-stamp").text(announcementData.user + " - " + announcementData.timestamp)
diff --git a/src/templates/index.html b/src/templates/index.html
index 7d5437a..8388290 100644
--- a/src/templates/index.html
+++ b/src/templates/index.html
@@ -57,8 +57,7 @@