start suggestions page

This commit is contained in:
ideclon 2022-12-19 23:21:09 +00:00
parent 6fbc2b7e9a
commit 2f29378f99
Signed by: ideclon
GPG Key ID: 3E186629301AFBFD
4 changed files with 52 additions and 1 deletions

View File

@ -1,4 +1,6 @@
<?php require("template/header.html")?>
You are connected to Mastodon as <b><span class='mastodon_user'></span></b> on server <b><span class="mastodon_server"></span></b>
<br><br><a href="suggestions.php">Go to your suggestions</a>
<?php $script = 'js/index.js'; require("template/footer.php")?>

View File

@ -49,4 +49,4 @@ export function message_box(type, message) {
message_box.style.display = 'block';
}
export { account, databases, functions, accountDetails };
export { client, account, databases, functions, accountDetails };

42
js/suggestions.js Normal file
View File

@ -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 += '<a href="' + element.post_link + '">' + element.post_link + ' - ' + element.points + ' points</a><br>';
});
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);
});

7
suggestions.php Normal file
View File

@ -0,0 +1,7 @@
<?php require("template/header.html")?>
You are connected to Mastodon as <b><span class='mastodon_user'></span></b> on server <b><span class="mastodon_server"></span></b>
<h4>Your suggestions</h4>
<span id="suggestions">You have no suggestions yet</span>
<?php $script = 'js/suggestions.js'; require("template/footer.php")?>