From f0798aaad070250bc05ae6d2bbb943314481b78b Mon Sep 17 00:00:00 2001 From: terrerox Date: Sat, 24 Dec 2022 17:26:45 -0400 Subject: [PATCH] fix --- src/store/posts.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/store/posts.js b/src/store/posts.js index 6329ce9..5767095 100644 --- a/src/store/posts.js +++ b/src/store/posts.js @@ -4,7 +4,7 @@ import { convertTimestampToDate, extractDataOfCaption } from '../helpers' export const usePostStore = defineStore('posts', { state: () => ({ isLoading: true, - posts: [], + posts: [] || JSON.parse(localStorage.getItem('posts')), post: {}, next: {}, previous: {} @@ -27,7 +27,9 @@ export const usePostStore = defineStore('posts', { } }) // set the response data - this.isLoading = false, + this.isLoading = false + const postArray = JSON.stringify(posts); + localStorage.setItem('posts', postArray); this.posts = posts; return posts }) @@ -50,14 +52,11 @@ export const usePostStore = defineStore('posts', { }) }, calculateNextAndPreviousPost(id) { - this.getAll() - .then(posts => { - const index = posts.findIndex(post => post.id === id) - const previousPost = index === 0 ? null : posts[index - 1] - const nextPost = index === posts.length - 1 ? null : posts[index + 1] - this.previous = previousPost - this.next = nextPost - }) + const index = this.posts.findIndex(post => post.id === id) + const previousPost = index === 0 ? null : this.posts[index - 1] + const nextPost = index === this.posts.length - 1 ? null : this.posts[index + 1] + this.previous = previousPost + this.next = nextPost } }, }) \ No newline at end of file