Added sync on reload
This commit is contained in:
@@ -13,6 +13,7 @@ const {
|
|||||||
nextArticle,
|
nextArticle,
|
||||||
prevArticle,
|
prevArticle,
|
||||||
fetchData,
|
fetchData,
|
||||||
|
sync,
|
||||||
getReadable,
|
getReadable,
|
||||||
setInitialLoad,
|
setInitialLoad,
|
||||||
showMessageForXSeconds,
|
showMessageForXSeconds,
|
||||||
@@ -78,6 +79,7 @@ async function shareUrl(url) {
|
|||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
setInitialLoad(false)
|
setInitialLoad(false)
|
||||||
await fetchData()
|
await fetchData()
|
||||||
|
sync(true)
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
setInitialLoad(true)
|
setInitialLoad(true)
|
||||||
console.log('set to true')
|
console.log('set to true')
|
||||||
|
|||||||
@@ -119,7 +119,14 @@ describe('RssFeeds', () => {
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
axios.post.mockResolvedValueOnce({ data: { content: '<html><body><article><p>full text</p></article></body></html>' } })
|
// axios.post is also hit by the sync triggered on mount, so branch on the
|
||||||
|
// URL rather than relying on call order via `mockResolvedValueOnce`.
|
||||||
|
axios.post.mockImplementation((url) => {
|
||||||
|
if (url === '/api/v1/article/sync') {
|
||||||
|
return Promise.resolve({ status: 200 })
|
||||||
|
}
|
||||||
|
return Promise.resolve({ data: { content: '<html><body><article><p>full text</p></article></body></html>' } })
|
||||||
|
})
|
||||||
|
|
||||||
const { layout } = useFeeds()
|
const { layout } = useFeeds()
|
||||||
layout.value = 'cards'
|
layout.value = 'cards'
|
||||||
@@ -199,7 +206,14 @@ describe('RssFeeds', () => {
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
axios.post.mockResolvedValueOnce({ data: { content: '<html><body><article><p>full text</p></article></body></html>' } })
|
// axios.post is also hit by the sync triggered on mount, so branch on the
|
||||||
|
// URL rather than relying on call order via `mockResolvedValueOnce`.
|
||||||
|
axios.post.mockImplementation((url) => {
|
||||||
|
if (url === '/api/v1/article/sync') {
|
||||||
|
return Promise.resolve({ status: 200 })
|
||||||
|
}
|
||||||
|
return Promise.resolve({ data: { content: '<html><body><article><p>full text</p></article></body></html>' } })
|
||||||
|
})
|
||||||
|
|
||||||
const wrapper = mount(RssFeeds)
|
const wrapper = mount(RssFeeds)
|
||||||
await flushPromises()
|
await flushPromises()
|
||||||
@@ -255,7 +269,8 @@ describe('RssFeeds', () => {
|
|||||||
expect(wrapper.find('.article-single .article-feature__title').text()).toBe('Article one')
|
expect(wrapper.find('.article-single .article-feature__title').text()).toBe('Article one')
|
||||||
// Same as in list view: the readable content is loaded on demand by
|
// Same as in list view: the readable content is loaded on demand by
|
||||||
// clicking the headline, not fetched automatically on entering the view.
|
// clicking the headline, not fetched automatically on entering the view.
|
||||||
expect(axios.post).not.toHaveBeenCalled()
|
// (axios.post is also hit by the sync triggered on mount.)
|
||||||
|
expect(axios.post).not.toHaveBeenCalledWith('/api/v1/article/read', expect.anything(), expect.anything())
|
||||||
expect(wrapper.find('.article-single .feed-original-link a').exists()).toBe(true)
|
expect(wrapper.find('.article-single .feed-original-link a').exists()).toBe(true)
|
||||||
|
|
||||||
await wrapper.find('.article-single .article-feature__title').trigger('click')
|
await wrapper.find('.article-single .article-feature__title').trigger('click')
|
||||||
|
|||||||
@@ -159,20 +159,22 @@ const fetchData = async () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
async function sync() {
|
async function sync(silent = false) {
|
||||||
try {
|
try {
|
||||||
const response = await axios.post('/api/v1/article/sync', {
|
const response = await axios.post('/api/v1/article/sync', {
|
||||||
user_id: parseInt(localStorage.getItem("user-id"))
|
user_id: parseInt(localStorage.getItem("user-id"))
|
||||||
}, authHeaders())
|
}, authHeaders())
|
||||||
|
|
||||||
if (response.status == 200) {
|
if (response.status == 200 && !silent) {
|
||||||
showMessageForXSeconds('Sync successful.', 5)
|
showMessageForXSeconds('Sync successful.', 5)
|
||||||
}
|
}
|
||||||
fetchData();
|
fetchData();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error sync', error)
|
console.error('Error sync', error)
|
||||||
|
if (!silent) {
|
||||||
showMessageForXSeconds(error, 5)
|
showMessageForXSeconds(error, 5)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupIntersectionObserver() {
|
function setupIntersectionObserver() {
|
||||||
|
|||||||
Reference in New Issue
Block a user