summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDevlin Junker <devlin.junker@gmail.com>2023-10-05 10:33:31 -0700
committerBenjamin Brahmer <info@b-brahmer.de>2023-10-06 08:18:41 +0200
commit60f319fe8aec339a26fb287fff94d6ab4a544795 (patch)
treeb513076632dea5d300d389c631c03d9ec6a7c851 /src
parent991facf2ee638713d2f2ef8b5197f32742d01804 (diff)
make ActionParams generic to make it clear what is available in each vuex file
Signed-off-by: Devlin Junker <devlin.junker@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/store/feed.ts41
-rw-r--r--src/store/folder.ts24
-rw-r--r--src/store/index.ts2
-rw-r--r--src/store/item.ts34
4 files changed, 58 insertions, 43 deletions
diff --git a/src/store/feed.ts b/src/store/feed.ts
index 2a62ff5fe..d3f1d8975 100644
--- a/src/store/feed.ts
+++ b/src/store/feed.ts
@@ -1,6 +1,6 @@
import _ from 'lodash'
-import { ActionParams, AppState } from '../store'
+import { ActionParams } from '../store'
import { Feed } from '../types/Feed'
import { FOLDER_MUTATION_TYPES, FEED_MUTATION_TYPES, FEED_ITEM_MUTATION_TYPES } from '../types/MutationTypes'
import { FolderService } from '../dataservices/folder.service'
@@ -24,11 +24,13 @@ export const FEED_ACTION_TYPES = {
}
export type FeedState = {
- feeds: Feed[]
+ feeds: Feed[];
+ unreadCount: number;
}
const state: FeedState = {
feeds: [],
+ unreadCount: 0,
}
const getters = {
@@ -38,7 +40,7 @@ const getters = {
}
export const actions = {
- async [FEED_ACTION_TYPES.FETCH_FEEDS]({ commit }: ActionParams) {
+ async [FEED_ACTION_TYPES.FETCH_FEEDS]({ commit }: ActionParams<FeedState>) {
const feeds = await FeedService.fetchAllFeeds()
commit(FEED_MUTATION_TYPES.SET_FEEDS, feeds.data.feeds)
@@ -48,7 +50,7 @@ export const actions = {
},
async [FEED_ACTION_TYPES.ADD_FEED](
- { commit }: ActionParams,
+ { commit }: ActionParams<FeedState>,
{ feedReq }: {
feedReq: {
url: string;
@@ -88,7 +90,10 @@ export const actions = {
}
},
- async [FEED_ACTION_TYPES.FEED_MARK_READ]({ commit }: ActionParams, { feed }: { feed: Feed }) {
+ async [FEED_ACTION_TYPES.FEED_MARK_READ](
+ { commit }: ActionParams<FeedState>,
+ { feed }: { feed: Feed },
+ ) {
// want to fetch feed so that we can retrieve the "highestItemId"
const response = await ItemService.fetchFeedItems(feed.id as number)
await FeedService.markRead({ feedId: feed.id as number, highestItemId: response.data.items[0].id })
@@ -101,7 +106,7 @@ export const actions = {
},
async [FEED_ACTION_TYPES.FEED_SET_PINNED](
- { commit }: ActionParams,
+ { commit }: ActionParams<FeedState>,
{ feed, pinned }: { feed: Feed, pinned: boolean },
) {
await FeedService.updateFeed({ feedId: feed.id as number, pinned })
@@ -110,7 +115,7 @@ export const actions = {
},
async [FEED_ACTION_TYPES.FEED_SET_ORDERING](
- { commit }: ActionParams,
+ { commit }: ActionParams<FeedState>,
{ feed, ordering }: { feed: Feed, ordering: FEED_ORDER },
) {
await FeedService.updateFeed({ feedId: feed.id as number, ordering })
@@ -119,7 +124,7 @@ export const actions = {
},
async [FEED_ACTION_TYPES.FEED_SET_FULL_TEXT](
- { commit }: ActionParams,
+ { commit }: ActionParams<FeedState>,
{ feed, fullTextEnabled }: { feed: Feed, fullTextEnabled: boolean },
) {
await FeedService.updateFeed({ feedId: feed.id as number, fullTextEnabled })
@@ -128,7 +133,7 @@ export const actions = {
},
async [FEED_ACTION_TYPES.FEED_SET_UPDATE_MODE](
- { commit }: ActionParams,
+ { commit }: ActionParams<FeedState>,
{ feed, updateMode }: { feed: Feed, updateMode: FEED_UPDATE_MODE },
) {
await FeedService.updateFeed({ feedId: feed.id as number, updateMode })
@@ -137,7 +142,7 @@ export const actions = {
},
async [FEED_ACTION_TYPES.FEED_SET_TITLE](
- { commit }: ActionParams,
+ { commit }: ActionParams<FeedState>,
{ feed, title }: { feed: Feed, title: string },
) {
await FeedService.updateFeed({ feedId: feed.id as number, title })
@@ -146,7 +151,7 @@ export const actions = {
},
async [FEED_ACTION_TYPES.FEED_DELETE](
- { commit }: ActionParams,
+ { commit }: ActionParams<FeedState>,
{ feed }: { feed: Feed },
) {
await FeedService.deleteFeed({ feedId: feed.id as number })
@@ -155,7 +160,7 @@ export const actions = {
},
async [FEED_ACTION_TYPES.MODIFY_FEED_UNREAD_COUNT](
- { commit, state }: ActionParams,
+ { commit, state }: ActionParams<FeedState>,
{ feedId, delta }: { feedId: number, delta: number },
) {
commit(FEED_MUTATION_TYPES.MODIFY_FEED_UNREAD_COUNT, { feedId, delta })
@@ -173,7 +178,7 @@ export const actions = {
export const mutations = {
[FEED_MUTATION_TYPES.SET_FEEDS](
- state: AppState,
+ state: FeedState,
feeds: Feed[],
) {
feeds.forEach(it => {
@@ -182,14 +187,14 @@ export const mutations = {
},
[FEED_MUTATION_TYPES.ADD_FEED](
- state: AppState,
+ state: FeedState,
feed: Feed,
) {
state.feeds.push(feed)
},
[FEED_MUTATION_TYPES.UPDATE_FEED](
- state: AppState,
+ state: FeedState,
newFeed: Feed,
) {
const feed = state.feeds.find((feed: Feed) => {
@@ -199,7 +204,7 @@ export const mutations = {
},
[FEED_MUTATION_TYPES.SET_FEED_ALL_READ](
- state: AppState,
+ state: FeedState,
feed: Feed,
) {
const priorFeed = state.feeds.find((stateFeed: Feed) => {
@@ -213,7 +218,7 @@ export const mutations = {
},
[FEED_MUTATION_TYPES.MODIFY_FEED_UNREAD_COUNT](
- state: AppState,
+ state: FeedState,
{ feedId, delta }: { feedId: number, delta: number },
) {
const feed = state.feeds.find((feed: Feed) => {
@@ -225,7 +230,7 @@ export const mutations = {
},
[FEED_MUTATION_TYPES.FEED_DELETE](
- state: AppState,
+ state: FeedState,
feedId: number,
) {
state.feeds = state.feeds.filter((feed: Feed) => {
diff --git a/src/store/folder.ts b/src/store/folder.ts
index d125c5b99..16c1c7f7c 100644
--- a/src/store/folder.ts
+++ b/src/store/folder.ts
@@ -1,6 +1,6 @@
import _ from 'lodash'
-import { AppState, ActionParams } from '../store'
+import { ActionParams } from '../store'
import { Folder } from '../types/Folder'
import { Feed } from '../types/Feed'
import { FOLDER_MUTATION_TYPES, FEED_MUTATION_TYPES } from '../types/MutationTypes'
@@ -29,27 +29,27 @@ const getters = {
}
export const actions = {
- async [FOLDER_ACTION_TYPES.FETCH_FOLDERS]({ commit }: ActionParams) {
+ async [FOLDER_ACTION_TYPES.FETCH_FOLDERS]({ commit }: ActionParams<FolderState>) {
const folders = await FolderService.fetchAllFolders()
commit(FOLDER_MUTATION_TYPES.SET_FOLDERS, folders.data.folders)
},
async [FOLDER_ACTION_TYPES.ADD_FOLDERS](
- { commit }: ActionParams,
+ { commit }: ActionParams<FolderState>,
{ folder }: { folder: Folder },
) {
const response = await FolderService.createFolder({ name: folder.name })
commit(FOLDER_MUTATION_TYPES.SET_FOLDERS, response.data.folders)
},
async [FOLDER_ACTION_TYPES.DELETE_FOLDER](
- { commit }: ActionParams,
+ { commit }: ActionParams<FolderState>,
{ folder }: { folder: Folder },
) {
await FolderService.deleteFolder({ id: folder.id })
commit(FOLDER_MUTATION_TYPES.DELETE_FOLDER, folder)
},
async [FOLDER_ACTION_TYPES.FOLDER_SET_NAME](
- { commit }: ActionParams,
+ { commit }: ActionParams<FolderState>,
{ folder, name }: { folder: Folder, name: string },
) {
await FolderService.renameFolder({ id: folder.id, name })
@@ -59,7 +59,7 @@ export const actions = {
export const mutations = {
[FOLDER_MUTATION_TYPES.SET_FOLDERS](
- state: AppState,
+ state: FolderState,
folders: Folder[],
) {
folders.forEach(it => {
@@ -70,7 +70,7 @@ export const mutations = {
},
[FOLDER_MUTATION_TYPES.DELETE_FOLDER](
- state: AppState,
+ state: FolderState,
folder: Folder,
) {
const index = state.folders.indexOf(folder)
@@ -78,7 +78,7 @@ export const mutations = {
},
[FEED_MUTATION_TYPES.SET_FEEDS](
- state: AppState,
+ state: FolderState,
feeds: Feed[],
) {
feeds.forEach(it => {
@@ -91,7 +91,7 @@ export const mutations = {
},
[FEED_MUTATION_TYPES.ADD_FEED](
- state: AppState,
+ state: FolderState,
feed: Feed,
) {
const folder = state.folders.find((folder: Folder) => { return folder.id === feed.folderId })
@@ -102,7 +102,7 @@ export const mutations = {
},
[FOLDER_MUTATION_TYPES.UPDATE_FOLDER](
- state: AppState,
+ state: FolderState,
newFolder: Folder,
) {
const folder = state.folders.find((f: Folder) => { return f.id === newFolder.id })
@@ -112,7 +112,7 @@ export const mutations = {
},
[FOLDER_MUTATION_TYPES.MODIFY_FOLDER_UNREAD_COUNT](
- state: AppState,
+ state: FolderState,
{ folderId, delta }: {folderId: number; delta: number },
) {
const folder = state.folders.find((f: Folder) => { return f.id === folderId })
@@ -122,7 +122,7 @@ export const mutations = {
},
[FEED_MUTATION_TYPES.SET_FEED_ALL_READ](
- state: AppState,
+ state: FolderState,
feed: Feed,
) {
const folder = state.folders.find((folder: Folder) => { return folder.id === feed.folderId })
diff --git a/src/store/index.ts b/src/store/index.ts
index 44f933740..26bf4e571 100644
--- a/src/store/index.ts
+++ b/src/store/index.ts
@@ -21,7 +21,7 @@ export const ACTIONS = {
export type AppState = FolderState & FeedState & ItemState & AppInfoState;
type Func = (name: string, value: unknown) => void;
-export type ActionParams = { commit: Func; dispatch: Func; state: AppState };
+export type ActionParams<T> = { commit: Func; dispatch: Func; state: T };
export default {
modules: {
diff --git a/src/store/item.ts b/src/store/item.ts
index 508b5c919..4d714305e 100644
--- a/src/store/item.ts
+++ b/src/store/item.ts
@@ -71,7 +71,7 @@ export const actions = {
* @param param1.start
*/
async [FEED_ITEM_ACTION_TYPES.FETCH_UNREAD](
- { commit }: ActionParams,
+ { commit }: ActionParams<ItemState>,
{ start }: { start: number } = { start: 0 },
) {
commit(FEED_ITEM_MUTATION_TYPES.SET_FETCHING, { key: 'unread', fetching: true })
@@ -98,7 +98,7 @@ export const actions = {
* @param param1.start
*/
async [FEED_ITEM_ACTION_TYPES.FETCH_ITEMS](
- { commit }: ActionParams,
+ { commit }: ActionParams<ItemState>,
{ start }: { start: number } = { start: 0 },
) {
commit(FEED_ITEM_MUTATION_TYPES.SET_FETCHING, { key: 'all', fetching: true })
@@ -127,7 +127,7 @@ export const actions = {
* @param param1.start
*/
async [FEED_ITEM_ACTION_TYPES.FETCH_STARRED](
- { commit }: ActionParams,
+ { commit }: ActionParams<ItemState>,
{ start }: { start: number } = { start: 0 },
) {
commit(FEED_ITEM_MUTATION_TYPES.SET_FETCHING, { key: 'starred', fetching: true })
@@ -158,7 +158,7 @@ export const actions = {
* @param param1.feedId
*/
async [FEED_ITEM_ACTION_TYPES.FETCH_FEED_ITEMS](
- { commit }: ActionParams,
+ { commit }: ActionParams<ItemState>,
{ feedId, start }: { feedId: number; start: number },
) {
commit(FEED_ITEM_MUTATION_TYPES.SET_FETCHING, { key: 'feed-' + feedId, fetching: true })
@@ -185,7 +185,7 @@ export const actions = {
* @param param1.folderId
*/
async [FEED_ITEM_ACTION_TYPES.FETCH_FOLDER_FEED_ITEMS](
- { commit }: ActionParams,
+ { commit }: ActionParams<ItemState>,
{ folderId, start }: { folderId: number; start: number },
) {
commit(FEED_ITEM_MUTATION_TYPES.SET_FETCHING, { key: 'folder-' + folderId, fetching: true })
@@ -212,7 +212,7 @@ export const actions = {
* @param param1.item
*/
[FEED_ITEM_ACTION_TYPES.MARK_READ](
- { commit, dispatch }: ActionParams,
+ { commit, dispatch }: ActionParams<ItemState>,
{ item }: { item: FeedItem },
) {
ItemService.markRead(item, true)
@@ -236,7 +236,7 @@ export const actions = {
* @param param1.item
*/
[FEED_ITEM_ACTION_TYPES.MARK_UNREAD](
- { commit, dispatch }: ActionParams,
+ { commit, dispatch }: ActionParams<ItemState>,
{ item }: { item: FeedItem},
) {
ItemService.markRead(item, false)
@@ -259,7 +259,7 @@ export const actions = {
* @param param1.item
*/
[FEED_ITEM_ACTION_TYPES.STAR_ITEM](
- { commit }: ActionParams,
+ { commit }: ActionParams<ItemState>,
{ item }: { item: FeedItem},
) {
ItemService.markStarred(item, true)
@@ -278,7 +278,7 @@ export const actions = {
* @param param1.item
*/
[FEED_ITEM_ACTION_TYPES.UNSTAR_ITEM](
- { commit }: ActionParams,
+ { commit }: ActionParams<ItemState>,
{ item }: { item: FeedItem},
) {
ItemService.markStarred(item, false)
@@ -290,14 +290,24 @@ export const actions = {
}
export const mutations = {
- [FEED_ITEM_MUTATION_TYPES.SET_SELECTED_ITEM](state: ItemState, { id }: { id: string }) {
+ [FEED_ITEM_MUTATION_TYPES.SET_SELECTED_ITEM](
+ state: ItemState,
+ { id }: { id: string },
+ ) {
state.selectedId = id
},
- [FEED_ITEM_MUTATION_TYPES.SET_PLAYING_ITEM](state: ItemState, item?: FeedItem) {
+
+ [FEED_ITEM_MUTATION_TYPES.SET_PLAYING_ITEM](
+ state: ItemState,
+ item?: FeedItem,
+ ) {
state.playingItem = item
},
- [FEED_ITEM_MUTATION_TYPES.SET_ITEMS](state: ItemState, items: FeedItem[]) {
+ [FEED_ITEM_MUTATION_TYPES.SET_ITEMS](
+ state: ItemState,
+ items: FeedItem[],
+ ) {
if (items) {
items.forEach(it => {
if (state.allItems.find((existing: FeedItem) => existing.id === it.id) === undefined) {