From 2f29378f99414f1273efbba523f099cec7bd33a1 Mon Sep 17 00:00:00 2001 From: ideclon Date: Mon, 19 Dec 2022 23:21:09 +0000 Subject: [PATCH] start suggestions page --- index.php | 2 ++ js/setup.js | 2 +- js/suggestions.js | 42 ++++++++++++++++++++++++++++++++++++++++++ suggestions.php | 7 +++++++ 4 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 js/suggestions.js create mode 100644 suggestions.php diff --git a/index.php b/index.php index a0186dd..fce35df 100644 --- a/index.php +++ b/index.php @@ -1,4 +1,6 @@ You are connected to Mastodon as on server +

Go to your suggestions + \ No newline at end of file diff --git a/js/setup.js b/js/setup.js index cb5bb89..d4cf972 100644 --- a/js/setup.js +++ b/js/setup.js @@ -49,4 +49,4 @@ export function message_box(type, message) { message_box.style.display = 'block'; } -export { account, databases, functions, accountDetails }; \ No newline at end of file +export { client, account, databases, functions, accountDetails }; \ No newline at end of file diff --git a/js/suggestions.js b/js/suggestions.js new file mode 100644 index 0000000..90d6957 --- /dev/null +++ b/js/suggestions.js @@ -0,0 +1,42 @@ +import {client, databases, accountDetails} from "./setup.js"; + +document.querySelectorAll('.mastodon_server').forEach((element) => { + element.innerHTML = accountDetails.prefs.user_server_uri +}); + +document.querySelectorAll('.mastodon_user').forEach((element) => { + element.innerHTML = JSON.parse(accountDetails.prefs.account_details).acct +}); + +let suggestions = await databases.listDocuments(APPWRITE_DB_ID, 'suggested', [ + Appwrite.Query.orderDesc('points') +]); + +suggestions = suggestions.documents; + +function display_suggestions(suggestions) { + let suggestion_body = ''; + + suggestions.forEach(element => { + suggestion_body += '' + element.post_link + ' - ' + element.points + ' points
'; + }); + + if(suggestion_body !== '') { + document.getElementById('suggestions').innerHTML = suggestion_body; + } +} + +display_suggestions(suggestions); + +console.log(suggestions); + +client.subscribe('databases.' + APPWRITE_DB_ID + '.collections.suggested.documents', async (response) => { + // suggestions.push(response.payload); + let suggestions = await databases.listDocuments(APPWRITE_DB_ID, 'suggested', [ + Appwrite.Query.orderDesc('points') + ]); + + suggestions = suggestions.documents; + + display_suggestions(suggestions); +}); \ No newline at end of file diff --git a/suggestions.php b/suggestions.php new file mode 100644 index 0000000..9233464 --- /dev/null +++ b/suggestions.php @@ -0,0 +1,7 @@ + +You are connected to Mastodon as on server + +

Your suggestions

+You have no suggestions yet + + \ No newline at end of file