diff --git a/src/hellocomputer/static/index.html b/src/hellocomputer/static/index.html
index b4ee779..30bbe4f 100644
--- a/src/hellocomputer/static/index.html
+++ b/src/hellocomputer/static/index.html
@@ -63,9 +63,8 @@
-
You'll be able to recover this file in the
- future
- with this name
+
+ You'll be able to recover this file in the future with this name
@@ -88,7 +87,7 @@
@@ -97,15 +96,17 @@
diff --git a/src/hellocomputer/static/script.js b/src/hellocomputer/static/script.js
index fd14e46..81f15d7 100644
--- a/src/hellocomputer/static/script.js
+++ b/src/hellocomputer/static/script.js
@@ -26,7 +26,6 @@ document.addEventListener("DOMContentLoaded", function () {
const textarea = document.getElementById('chatTextarea');
const sendButton = document.getElementById('sendButton');
-const sessions = document.getElementById('userSessions');
const chatMessages = document.querySelector('.chat-messages');
// Auto resize textarea
@@ -167,14 +166,24 @@ document.addEventListener("DOMContentLoaded", function () {
// Function to get the user sessions
document.addEventListener("DOMContentLoaded", function () {
const sessionsButton = document.getElementById('loadSessionsButton');
+ const sessions = document.getElementById('userSessions');
+
sessionsButton.addEventListener('click', async function fetchSessions() {
try {
const response = await fetch('/sessions');
if (!response.ok) {
throw new Error('Network response was not ok ' + response.statusText);
}
- const data = await response.text();
- sessions.innerHTML = data;
+ const data = JSON.parse(await response.text());
+ sessions.innerHTML = '';
+ data.forEach(item => {
+ const listItem = document.createElement('li');
+ const button = document.createElement('button');
+ button.textContent = item;
+ button.addEventListener("click", function () { alert(`You clicked on ${item}`); });
+ listItem.appendChild(button);
+ sessions.appendChild(listItem);
+ });
} catch (error) {
sessions.innerHTML = 'Error: ' + error.message;
}
diff --git a/src/hellocomputer/users.py b/src/hellocomputer/users.py
index e097aa8..2f65e94 100644
--- a/src/hellocomputer/users.py
+++ b/src/hellocomputer/users.py
@@ -91,16 +91,23 @@ class OwnershipDB(DDB):
return sid
def sessions(self, user_email: str) -> List[str]:
- return (
- self.db.sql(f"""
+ try:
+ return (
+ self.db.sql(f"""
SELECT
sid
FROM
'{self.path_prefix}/*.csv'
WHERE
- email = '{user_email}'
+ email = '{user_email}
+ ORDER BY
+ timestamp ASC
+ LIMIT 10'
""")
- .pl()
- .to_series()
- .to_list()
- )
+ .pl()
+ .to_series()
+ .to_list()
+ )
+ # If the table does not exist
+ except duckdb.duckdb.IOException:
+ return []