Skip to content

Commit

Permalink
Set last modified on first load
Browse files Browse the repository at this point in the history
  • Loading branch information
ml-evs committed Aug 22, 2023
1 parent b713604 commit 01e880e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
15 changes: 10 additions & 5 deletions webapp/src/views/CollectionPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
Unsaved changes
</span>
<span v-if="data_loaded && lastModified" class="navbar-text small mx-2"
><i>Last saved {{ lastModified }}</i></span
><i>Last saved: {{ lastModified }}</i></span
>
<font-awesome-icon
icon="save"
Expand Down Expand Up @@ -65,17 +65,22 @@ export default {
async getCollection() {
await getCollectionData(this.collection_id);
this.data_loaded = true;
this.setLastModified();
},
leavePageWarningListener(event) {
event.preventDefault;
return (event.returnValue =
"Unsaved changes present. Would you like to leave without saving?");
},
setLastModified() {
let item_date = this.collection_data.last_modified;
// API dates are in UTC but missing Z suffix
const save_date = new Date(item_date + "Z");
this.lastModified = formatDistanceToNow(save_date, { addSuffix: true });
let item_date = this.collection_data.last_modified || this.collection_data.date;
if (item_date == null) {
this.lastModified = "Unknown";
} else {
// API dates are in UTC but missing Z suffix
const save_date = new Date(item_date + "Z");
this.lastModified = formatDistanceToNow(save_date, { addSuffix: true });
}
},
},
computed: {
Expand Down
8 changes: 5 additions & 3 deletions webapp/src/views/EditPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ export default {
console.log(`calling update on block ${block_id}`);
updateBlockFromServer(this.item_id, block_id, this.item_data.blocks_obj[block_id]);
});
this.setLastModified();
});
},
leavePageWarningListener(event) {
Expand All @@ -192,10 +193,11 @@ export default {
let item_date = this.item_data.last_modified || this.item_data.date;
if (item_date == null) {
this.lastModified = "Unknown";
} else {
// API dates are in UTC but missing Z suffix
const save_date = new Date(item_date);
this.lastModified = formatDistanceToNow(save_date, { addSuffix: true });
}
// API dates are in UTC but missing Z suffix
const save_date = new Date(item_date);
this.lastModified = formatDistanceToNow(save_date, { addSuffix: true });
},
},
computed: {
Expand Down

0 comments on commit 01e880e

Please sign in to comment.