Readjusted code to not use localstorage, and just used redux for indicator

This commit is contained in:
Eshwar Tangirala
2025-05-22 20:10:52 -04:00
parent 0199a36238
commit 7b33717333
4 changed files with 18 additions and 27 deletions

View File

@@ -40,29 +40,18 @@ export const treeSlice = createSlice({
}
})
},
setHasNewEntries: (state, action: PayloadAction<{ feedId: number; value: boolean }>) => {
if (!state.rootCategory) return
visitCategoryTree(state.rootCategory, category => {
category.feeds = category.feeds.map(feed =>
feed.id === action.payload.feedId ? { ...feed, hasNewEntries: action.payload.value } : feed
)
})
},
},
extraReducers: builder => {
builder.addCase(reloadTree.fulfilled, (state, action) => {
visitCategoryTree(action.payload, category => {
category.feeds = category.feeds.map(feed => {
const storageKey = `feed-${feed.id}-unread`
const existing = localStorage.getItem(storageKey)
const prevUnread = Number.parseInt(existing || "0", 10)
const isNewFeed = existing === null
const hasNewEntries = isNewFeed ? true : feed.unread > prevUnread
if (!isNewFeed) {
localStorage.setItem(storageKey, feed.unread.toString())
}
return {
...feed,
hasNewEntries,
}
})
})
state.rootCategory = action.payload
})
builder.addCase(collapseTreeCategory.pending, (state, action) => {
@@ -85,4 +74,4 @@ export const treeSlice = createSlice({
},
})
export const { setMobileMenuOpen, toggleSidebar, incrementUnreadCount } = treeSlice.actions
export const { setMobileMenuOpen, toggleSidebar, incrementUnreadCount, setHasNewEntries } = treeSlice.actions