Skip to content

Commit

Permalink
refactor(ControlPanel): update logic of prompts
Browse files Browse the repository at this point in the history
  • Loading branch information
letwebdev committed Feb 23, 2024
1 parent b7eba8b commit e307191
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions src/components/ControlPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@ import type { ListName } from "@/types/hackerNews"
const { settings } = useSettingsStore()
const coreData = useCoreDataStore()
const fetchingData = useFetchingDataStore()
const { fetchLists, fetchList, resetItemsInQueue } = fetchingData
const { fetchLists, resetItemsInQueue } = fetchingData
const liveDataCacheInitialized = useFetchingDataStore().getLiveDataCacheInitializationState
const selected: RemovableRef<ListName[]> = useLocalStorage("selectedLists", ["topstories"])
function fetchMore() {
fetchingData.promptOfFetching = "Fetching selected lists..."
resetItemsInQueue()
fetchSelectedLists()
}
function fetchSelectedLists() {
fetchLists(selected.value)
async function fetchSelectedLists() {
await fetchLists(selected.value)
fetchingData.promptOfFetching = ""
}
function refresh() {
Expand All @@ -29,22 +31,12 @@ function clearDisplayedItems() {
coreData.items = []
}
// Init: Fetch stories
fetchingData.promptOfFetching = "Fetching selected lists..."
// TODO refresh live data when refresh()
let interValId: number | null = window.setInterval(() => {
watchEffect(() => {
if (liveDataCacheInitialized.value) {
fetchList(selected.value[0]).then(() => {
fetchingData.promptOfFetching = ""
})
/* fetchList("maxitem") */
if (interValId) {
clearInterval(interValId)
interValId = null
}
fetchMore()
}
}, 200)
})
function scrolledToBottom(): boolean {
return window.innerHeight + Math.round(window.scrollY) + 1 >= document.body.offsetHeight
Expand Down

0 comments on commit e307191

Please sign in to comment.