Add more comment and pointer on usernames

This commit is contained in:
Marco Realacci 2023-01-11 23:25:24 +01:00
parent 6816f24700
commit 11dfbe6658
4 changed files with 49 additions and 6 deletions

View file

@ -3,12 +3,19 @@ export default {
props: ["user_id", "name", "date", "comments", "likes", "photo_id", "liked"], props: ["user_id", "name", "date", "comments", "likes", "photo_id", "liked"],
data: function () { data: function () {
return { return {
// Data for the modal
modalTitle: "Modal Title", modalTitle: "Modal Title",
modalMsg: "Modal Message", modalMsg: "Modal Message",
// Whether the user is logged in
logged_in: true, logged_in: true,
} }
}, },
methods: { methods: {
// Function to show a modal
// can be called by any view or component
// title: title of the modal
// message: message to show in the modal
showModal(title, message) { showModal(title, message) {
this.modalTitle = title this.modalTitle = title
this.modalMsg = message this.modalMsg = message
@ -16,9 +23,14 @@ export default {
// Simulate a click on the hidden modal button to open it // Simulate a click on the hidden modal button to open it
this.$refs.openModal.click() this.$refs.openModal.click()
}, },
// Sets the login status to true
// to show the navigation buttons
setLoggedIn() { setLoggedIn() {
this.logged_in = true this.logged_in = true
}, },
// Disconnects the current logged in user
logout() { logout() {
localStorage.removeItem("token") localStorage.removeItem("token")
sessionStorage.removeItem("token") sessionStorage.removeItem("token")
@ -27,6 +39,7 @@ export default {
} }
}, },
// Called when the root view is mounted
mounted() { mounted() {
// Check if the user is already logged in // Check if the user is already logged in
this.$axiosUpdate() this.$axiosUpdate()

View file

@ -96,7 +96,7 @@ export default {
<div class="row"> <div class="row">
<div class="col-10"> <div class="col-10">
<div class="card-body"> <div class="card-body">
<h5 @click="visitUser" class="card-title">{{ name }}</h5> <h5 @click="visitUser" class="card-title" style="cursor: pointer">{{ name }}</h5>
<p class="card-text">{{ new Date(Date.parse(date)) }}</p> <p class="card-text">{{ new Date(Date.parse(date)) }}</p>
</div> </div>
</div> </div>

View file

@ -93,7 +93,7 @@ export default {
<div class="col-5"> <div class="col-5">
<div class="card-body h-100 d-flex align-items-center"> <div class="card-body h-100 d-flex align-items-center">
<a @click="visit"> <a @click="visit">
<h5 class="card-title mb-0">{{ username }}</h5> <h5 class="card-title mb-0" style="cursor: pointer">{{ username }}</h5>
</a> </a>
</div> </div>
</div> </div>

View file

@ -2,25 +2,42 @@
export default { export default {
data: function () { data: function () {
return { return {
// Whether the content is loading
// to show the loading spinner
loading: false, loading: false,
// Stream data from the server
stream_data: [], stream_data: [],
// Whether the data has ended
// to stop loading more data with the infinite scroll
data_ended: false, data_ended: false,
// Parameters to load data dynamically when scrolling
start_idx: 0, start_idx: 0,
limit: 1, limit: 1,
// Shows the retry button
loadingError: false, loadingError: false,
} }
}, },
methods: { methods: {
// Reload the whole page content
// fetching it again from the server
async refresh() { async refresh() {
// this way we are sure that we fill the first page // Limits the number of posts to load based on the window height
// 450 is a bit more of the max height of a post // to avoid loading too many posts at once
// todo: may not work in 4k screens :/ // 450px is (a bit more) of the height of a single post
this.limit = Math.round(window.innerHeight / 450); this.limit = Math.round(window.innerHeight / 450);
// Reset the parameters and the data
this.start_idx = 0; this.start_idx = 0;
this.data_ended = false; this.data_ended = false;
this.stream_data = []; this.stream_data = [];
this.loadContent(); this.loadContent();
}, },
// Requests data from the server asynchronously
async loadContent() { async loadContent() {
this.loading = true; this.loading = true;
@ -33,17 +50,30 @@ export default {
return return
} }
// If the response is empty or shorter than the limit
// then there is no more data to load
if (response.data.length == 0 || response.data.length < this.limit) this.data_ended = true; if (response.data.length == 0 || response.data.length < this.limit) this.data_ended = true;
this.stream_data = this.stream_data.concat(response.data); this.stream_data = this.stream_data.concat(response.data);
// Finished loading, hide the spinner
this.loading = false; this.loading = false;
}, },
// Loads more data when the user scrolls down
// (this is called by the IntersectionObserver component)
loadMore() { loadMore() {
// Avoid loading more content if the data has ended
if (this.loading || this.data_ended) return if (this.loading || this.data_ended) return
// Increase the start index and load more content
this.start_idx += this.limit this.start_idx += this.limit
this.loadContent() this.loadContent()
}, },
}, },
// Called when the view is mounted
mounted() { mounted() {
// Start loading the content
this.refresh(); this.refresh();
} }
} }
@ -66,7 +96,7 @@ export default {
:comments="item.comments" :likes="item.likes" :liked="item.liked" /> :comments="item.comments" :likes="item.likes" :liked="item.liked" />
</div> </div>
<div v-if="data_ended" class="alert alert-secondary text-center" role="alert"> <div v-if="(data_ended && !(stream_data.length == 0))" class="alert alert-secondary text-center" role="alert">
This is the end of your stream. Hooray! 👻 This is the end of your stream. Hooray! 👻
</div> </div>