Skip to content

Commit

Permalink
Use loadInitialNotes() to remove page refreshing when trying to view …
Browse files Browse the repository at this point in the history
…new notes
  • Loading branch information
katniny committed Sep 27, 2024
1 parent 2c37105 commit f99a7d5
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 95 deletions.
2 changes: 1 addition & 1 deletion assets/css/mainSite.css
Original file line number Diff line number Diff line change
Expand Up @@ -2918,7 +2918,7 @@ textarea.borderBlack:focus {

/* Home Page */
.animateGradient {
background: linear-gradient(45deg, var(--main-color), #ff4866);
background: linear-gradient(45deg, pink, purple);
background-size: 200% 200%;
background-clip: text;
-webkit-background-clip: text;
Expand Down
177 changes: 96 additions & 81 deletions assets/js/ts_fas_acih.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ const pathName = pageURL.pathname;
let isOnDesktopApp = null;

// TransSocial Version
let transsocialVersion = "v2024.9.23";
let transsocialUpdate = "v2024923-1";
let transsocialVersion = "v2024.9.27";
let transsocialUpdate = "v2024927-1";
let transsocialReleaseVersion = "pre-alpha";

const notices = document.getElementsByClassName("version-notice");
Expand Down Expand Up @@ -1221,9 +1221,15 @@ if (pathName === "/home" || pathName === "/home.html" || pathName === "/u" || pa

fetchAutoplayPreference(); // call on start

// Reload page
// show notes without refreshing
// revolutionary tech y'all
function loadNotesFromButton() {
window.location.reload();
// remove existing notes
const notes = document.querySelectorAll(".note");
notes.forEach(note => note.remove());

// load the new notes
loadInitalNotes();
}

// Note Rendering
Expand Down Expand Up @@ -5122,96 +5128,105 @@ document.body.addEventListener('click', function (event) {

// Direct Messages
if (pathName === "/messages") {
const url = new URL(window.location.href);
const dmParam = url.searchParams.get("id");

firebase.auth().onAuthStateChanged((user) => {
if (user) {
firebase.database().ref(`users/${user.uid}/openDMs`).on("value", (snapshot) => {
const openDMs = snapshot.val() || {}; // Handle the case where openDMs doesn't exist
if (!dmParam) {
firebase.database().ref(`users/${user.uid}/openDMs`).on("value", (snapshot) => {
const openDMs = snapshot.val() || {}; // Handle the case where openDMs doesn't exist

const dmContainer = document.getElementById("openChats");
dmContainer.innerHTML = "";
const dmContainer = document.getElementById("openChats");
dmContainer.innerHTML = "";

if (Object.keys(openDMs).length > 0) {
if (document.getElementById("noDMsOpen")) {
document.getElementById("noDMsOpen").remove();
}
if (Object.keys(openDMs).length > 0) {
if (document.getElementById("noDMsOpen")) {
document.getElementById("noDMsOpen").remove();
}

// Create divs for each DM
for (const dmId in openDMs) {
const dmDiv = document.createElement("div");
dmDiv.id = dmId;
dmDiv.classList.add("person");
firebase.database().ref(`dms/${dmId}`).on("value", (snapshot) => {
const dmData = snapshot.val();

if (user.uid === dmData.user1) {
const otherPersonPfp = document.createElement("img");
const otherPersonDisplay = document.createElement("span");
const lastMessageSent = document.createElement("span");

firebase.database().ref(`users/${dmData.user2}`).once("value", (snapshot) => {
const otherPerson = snapshot.val();

// Get pfp
otherPersonPfp.src = `https://firebasestorage.googleapis.com/v0/b/${firebaseConfig.storageBucket}/o/images%2Fpfp%2F${dmData.user2}%2F${otherPerson.pfp}?alt=media`;
otherPersonPfp.setAttribute("draggable", "false");
otherPersonPfp.classList.add("pfp");
dmDiv.appendChild(otherPersonPfp);
dmContainer.appendChild(dmDiv);

// Get display
otherPersonDisplay.textContent = otherPerson.display;
otherPersonDisplay.classList.add("display");
dmDiv.appendChild(otherPersonDisplay);
dmContainer.appendChild(dmDiv);

// Get last message, if available
if (dmData.messages) {
// Create divs for each DM
for (const dmId in openDMs) {
const dmDiv = document.createElement("div");
dmDiv.id = dmId;
dmDiv.classList.add("person");
firebase.database().ref(`dms/${dmId}`).on("value", (snapshot) => {
const dmData = snapshot.val();

if (user.uid === dmData.user1) {
const otherPersonPfp = document.createElement("img");
const otherPersonDisplay = document.createElement("span");
const lastMessageSent = document.createElement("span");

firebase.database().ref(`users/${dmData.user2}`).once("value", (snapshot) => {
const otherPerson = snapshot.val();

// Get pfp
otherPersonPfp.src = `https://firebasestorage.googleapis.com/v0/b/${firebaseConfig.storageBucket}/o/images%2Fpfp%2F${dmData.user2}%2F${otherPerson.pfp}?alt=media`;
otherPersonPfp.setAttribute("draggable", "false");
otherPersonPfp.classList.add("pfp");
dmDiv.appendChild(otherPersonPfp);
dmContainer.appendChild(dmDiv);

} else {
lastMessageSent.textContent = `You and ${otherPerson.username} haven't chatted yet!`;
lastMessageSent.classList.add("lastMessageSent");
dmDiv.appendChild(lastMessageSent);
// Get display
otherPersonDisplay.textContent = otherPerson.display;
otherPersonDisplay.classList.add("display");
dmDiv.appendChild(otherPersonDisplay);
dmContainer.appendChild(dmDiv);
}
})
} else {
const otherPersonPfp = document.createElement("img");
const otherPersonDisplay = document.createElement("span");
const lastMessageSent = document.createElement("p");

firebase.database().ref(`users/${dmData.user1}`).once("value", (snapshot) => {
const otherPerson = snapshot.val();
// Get last message, if available
if (dmData.messages) {

// Get pfp
otherPersonPfp.src = `https://firebasestorage.googleapis.com/v0/b/${firebaseConfig.storageBucket}/o/images%2Fpfp%2F${dmData.user1}%2F${otherPerson.pfp}?alt=media`;
otherPersonPfp.setAttribute("draggable", "false");
otherPersonPfp.classList.add("pfp");
dmDiv.appendChild(otherPersonPfp);
dmContainer.appendChild(dmDiv);
} else {
lastMessageSent.textContent = `You and ${otherPerson.username} haven't chatted yet!`;
lastMessageSent.classList.add("lastMessageSent");
dmDiv.appendChild(lastMessageSent);
dmContainer.appendChild(dmDiv);
}
})
} else {
const otherPersonPfp = document.createElement("img");
const otherPersonDisplay = document.createElement("span");
const lastMessageSent = document.createElement("p");

firebase.database().ref(`users/${dmData.user1}`).once("value", (snapshot) => {
const otherPerson = snapshot.val();

// Get pfp
otherPersonPfp.src = `https://firebasestorage.googleapis.com/v0/b/${firebaseConfig.storageBucket}/o/images%2Fpfp%2F${dmData.user1}%2F${otherPerson.pfp}?alt=media`;
otherPersonPfp.setAttribute("draggable", "false");
otherPersonPfp.classList.add("pfp");
dmDiv.appendChild(otherPersonPfp);
dmContainer.appendChild(dmDiv);

// Get display
otherPersonDisplay.textContent = otherPerson.display;
otherPersonDisplay.classList.add("display");
dmDiv.appendChild(otherPersonDisplay);
dmContainer.appendChild(dmDiv);
// Get display
otherPersonDisplay.textContent = otherPerson.display;
otherPersonDisplay.classList.add("display");
dmDiv.appendChild(otherPersonDisplay);
dmContainer.appendChild(dmDiv);

// Get last message, if available
if (dmData.messages) {
// Get last message, if available
if (dmData.messages) {

} else {
lastMessageSent.textContent = `You and ${otherPerson.username} haven't chatted yet!`;
lastMessageSent.classList.add("lastMessageSent");
dmDiv.appendChild(lastMessageSent);
dmContainer.appendChild(dmDiv);
}
})
}
})
} else {
lastMessageSent.textContent = `You and ${otherPerson.username} haven't chatted yet!`;
lastMessageSent.classList.add("lastMessageSent");
dmDiv.appendChild(lastMessageSent);
dmContainer.appendChild(dmDiv);
}
})
}
})
}
} else {
document.getElementById("noDMsOpen").style.display = "block";
}
} else {
document.getElementById("noDMsOpen").style.display = "block";
}
})
})
} else {
// hide open dms & show current
document.getElementById("dmNotOpen").remove();
document.getElementById("dms").style.display = "block";
}
}
})

Expand Down
5 changes: 2 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@
<br />
<br />
<br />
<h1 style="font-size: 3em;">A Safe Place for
<br /> <span class="animateGradient">Everyone</span>
</h1>
<h1 style="font-size: 2.5em;">A Safe Place for</h1>
<h1 class="animateGradient" style="font-size: 3em;">Everyone</h1>
<p>A social media platform where you can truly be yourself, together.</p>

<br />
Expand Down
26 changes: 16 additions & 10 deletions messages.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,26 @@ <h3 id="greetingManager">Hello, {user}</h3>
<!--<button class="active" style="border-right: 1px solid gray;">All Notes</button><button>Following</button>-->
</div>

<button onclick="startNewChat()" style="margin-left: 15px;"><i class="fa-solid fa-message"></i> New Chat</button>
<div id="dmNotOpen">
<button onclick="startNewChat()" style="margin-left: 15px;"><i class="fa-solid fa-message"></i> New Chat</button>

<br />
<br />
<br />
<br />

<div class="openChats" id="openChats">
<div id="noDMsOpen">
<p>You don't have any DMs open!</p>
<p style="color: var(--text-semi-transparent); margin-top: 0px;">Start a conversation!</p>
</div>
<div class="openChats" id="openChats">
<div id="noDMsOpen">
<p>You don't have any DMs open!</p>
<p style="color: var(--text-semi-transparent); margin-top: 0px;">Start a conversation!</p>
</div>

<div id="openDMs">
<div id="openDMs">

</div>
</div>
</div>
</div>

<div id="dms" style="display: none;">
<h1>hi</h1>
</div>

<!-- Please Donate -->
Expand Down
8 changes: 8 additions & 0 deletions updates.html
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ <h1 id="selectedFilter" style="text-decoration: underline; margin-bottom: 5px;">
<div id="prealphaVersions">
<p>Trying to find older updates? You may be interested in the InDev tab, since TransSocial is no longer in InDev!</p>

<div class="update">
<h2>v2024.9.27_pre-alpha</h2>
<h3 style="color: var(--text-semi-transparent);">Released: September 27, 2024</h3>
<li>The page will no longer refresh when pressing "New Notes" button</li>
</div>

<br />

<div class="update">
<h2>v2024.9.23_pre-alpha</h2>
<h3 style="color: var(--text-semi-transparent);">Released: September 23, 2024</h3>
Expand Down

0 comments on commit f99a7d5

Please sign in to comment.