Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
terrerox committed Dec 24, 2022
1 parent ac823db commit f0798aa
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/store/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}
Expand All @@ -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
})
Expand All @@ -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
}
},
})

1 comment on commit f0798aa

@vercel
Copy link

@vercel vercel bot commented on f0798aa Dec 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.