accounts approved, video player testing, bookmark collections
This commit is contained in:
mgabdev
2020-12-17 01:34:00 -05:00
parent 04053c0e31
commit 5a37a7090e
88 changed files with 688 additions and 395 deletions

View File

@@ -1,7 +1,9 @@
import {
BOOKMARK_COLLECTIONS_FETCH_REQUEST,
BOOKMARK_COLLECTIONS_FETCH_SUCCESS,
BOOKMARK_COLLECTIONS_FETCH_FAIL,
ALBUMS_FETCH_REQUEST,
ALBUMS_FETCH_SUCCESS,
ALBUMS_FETCH_FAIL,
ALBUMS_CREATE_SUCCESS,
ALBUMS_REMOVE_REQUEST,
} from '../actions/bookmarks'
import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable'
@@ -12,49 +14,32 @@ const initialState = ImmutableMap({
isError: false,
})
const normalizeBookmarkCollection = (bookmarkCollection) => {
return {
id: shortcut.id,
shortcut_type: 'account',
shortcut_id: shortcut.shortcut_id,
title: shortcut.shortcut.acct,
image: shortcut.shortcut.avatar_static,
to: `/${shortcut.shortcut.acct}`,
}
}
const normalizeBookmarkCollections = (shortcuts) => {
return fromJS(shortcuts.map((shortcut) => {
return normalizeShortcut(shortcut)
}))
}
export default function albums(state = initialState, action) {
switch(action.type) {
case SHORTCUTS_FETCH_REQUEST:
case ALBUMS_FETCH_REQUEST:
return state.withMutations((map) => {
map.set('isLoading', true)
map.set('isFetched', false)
map.set('isError', false)
})
case SHORTCUTS_FETCH_SUCCESS:
case ALBUMS_FETCH_SUCCESS:
return state.withMutations((map) => {
map.set('items', normalizeShortcuts(action.shortcuts))
map.set('items', fromJS(action.bookmarkCollections))
map.set('isLoading', false)
map.set('isFetched', true)
map.set('isError', false)
})
case SHORTCUTS_FETCH_FAIL:
case ALBUMS_FETCH_FAIL:
return state.withMutations((map) => {
map.set('isLoading', false)
map.set('isFetched', true)
map.set('isError', true)
})
case BOOKMARK_COLLECTIONS_CREATE_REQUEST:
return state.update('items', list => list.push(fromJS(normalizeShortcut(action.shortcut))))
case BOOKMARK_COLLECTIONS_REMOVE_REQUEST:
case ALBUMS_CREATE_SUCCESS:
return state.update('items', list => list.push(fromJS(action.bookmarkCollection)))
case ALBUMS_REMOVE_REQUEST:
return state.update('items', list => list.filterNot((item) => {
return `${item.get('id')}` === `${action.shortcutId}`
return item.get('id') === action.bookmarkCollectionId
}))
default:
return state

View File

@@ -2,6 +2,8 @@ import {
BOOKMARK_COLLECTIONS_FETCH_REQUEST,
BOOKMARK_COLLECTIONS_FETCH_SUCCESS,
BOOKMARK_COLLECTIONS_FETCH_FAIL,
BOOKMARK_COLLECTIONS_CREATE_SUCCESS,
BOOKMARK_COLLECTIONS_REMOVE_REQUEST,
} from '../actions/bookmarks'
import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable'
@@ -12,49 +14,32 @@ const initialState = ImmutableMap({
isError: false,
})
const normalizeBookmarkCollection = (bookmarkCollection) => {
return {
id: shortcut.id,
shortcut_type: 'account',
shortcut_id: shortcut.shortcut_id,
title: shortcut.shortcut.acct,
image: shortcut.shortcut.avatar_static,
to: `/${shortcut.shortcut.acct}`,
}
}
const normalizeBookmarkCollections = (shortcuts) => {
return fromJS(shortcuts.map((shortcut) => {
return normalizeShortcut(shortcut)
}))
}
export default function bookmark_collections(state = initialState, action) {
switch(action.type) {
case SHORTCUTS_FETCH_REQUEST:
case BOOKMARK_COLLECTIONS_FETCH_REQUEST:
return state.withMutations((map) => {
map.set('isLoading', true)
map.set('isFetched', false)
map.set('isError', false)
})
case SHORTCUTS_FETCH_SUCCESS:
case BOOKMARK_COLLECTIONS_FETCH_SUCCESS:
return state.withMutations((map) => {
map.set('items', normalizeShortcuts(action.shortcuts))
map.set('items', fromJS(action.bookmarkCollections))
map.set('isLoading', false)
map.set('isFetched', true)
map.set('isError', false)
})
case SHORTCUTS_FETCH_FAIL:
case BOOKMARK_COLLECTIONS_FETCH_FAIL:
return state.withMutations((map) => {
map.set('isLoading', false)
map.set('isFetched', true)
map.set('isError', true)
})
case BOOKMARK_COLLECTIONS_CREATE_REQUEST:
return state.update('items', list => list.push(fromJS(normalizeShortcut(action.shortcut))))
case BOOKMARK_COLLECTIONS_CREATE_SUCCESS:
return state.update('items', list => list.push(fromJS(action.bookmarkCollection)))
case BOOKMARK_COLLECTIONS_REMOVE_REQUEST:
return state.update('items', list => list.filterNot((item) => {
return `${item.get('id')}` === `${action.shortcutId}`
return item.get('id') === action.bookmarkCollectionId
}))
default:
return state

View File

@@ -2,6 +2,8 @@ import { combineReducers } from 'redux-immutable'
import { loadingBarReducer } from 'react-redux-loading-bar'
import accounts from './accounts'
import accounts_counters from './accounts_counters'
import albums from './albums'
import bookmark_collections from './bookmark_collections'
import chats from './chats'
import chat_conversation_lists from './chat_conversation_lists'
import chat_conversation_messages from './chat_conversation_messages'
@@ -52,6 +54,7 @@ import user_lists from './user_lists'
const reducers = {
accounts,
accounts_counters,
bookmark_collections,
chats,
chat_conversation_lists,
chat_conversation_messages,

View File

@@ -16,17 +16,16 @@ import {
} from '../actions/bookmarks'
import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
const initialMap = ImmutableMap({
next: null,
loaded: false,
isLoading: false,
items: ImmutableList(),
})
const initialState = ImmutableMap({
bookmarks: ImmutableMap({
next: null,
loaded: false,
items: ImmutableList(),
}),
favorites: ImmutableMap({
next: null,
loaded: false,
items: ImmutableList(),
}),
bookmarks: ImmutableMap(),
favorites: initialMap,
});
const normalizeList = (state, listType, statuses, next) => {
@@ -62,14 +61,30 @@ export default function statusLists(state = initialState, action) {
switch (action.type) {
case BOOKMARKED_STATUSES_FETCH_REQUEST:
case BOOKMARKED_STATUSES_EXPAND_REQUEST:
return state.setIn(['bookmarks', 'isLoading'], true);
return state.updateIn(['bookmarks', action.bookmarkCollectionId], initialMap, map => map.set('isLoading', true))
case BOOKMARKED_STATUSES_FETCH_FAIL:
case BOOKMARKED_STATUSES_EXPAND_FAIL:
return state.setIn(['bookmarks', 'isLoading'], false);
return state.setIn(['bookmarks', action.bookmarkCollectionId, 'isLoading'], false);
case BOOKMARKED_STATUSES_FETCH_SUCCESS:
return normalizeList(state, 'bookmarks', action.statuses, action.next);
console.log("BOOKMARKED_STATUSES_FETCH_SUCCESS:", action)
try {
return state.updateIn(['bookmarks', action.bookmarkCollectionId], listMap => listMap.withMutations(map => {
map.set('next', action.next);
map.set('loaded', true);
map.set('isLoading', false);
map.set('items', ImmutableList(action.statuses.map(item => item.id)));
}))
} catch (error) {
console.log("error:", state, error)
}
return state
case BOOKMARKED_STATUSES_EXPAND_SUCCESS:
return appendToList(state, 'bookmarks', action.statuses, action.next);
return state.updateIn(['bookmarks', action.bookmarkCollectionId], listMap => listMap.withMutations(map => {
map.set('next', action.next);
map.set('isLoading', false);
map.set('items', map.get('items').concat(action.statuses.map(item => item.id)));
}))
case FAVORITED_STATUSES_FETCH_REQUEST:
case FAVORITED_STATUSES_EXPAND_REQUEST:
return state.setIn(['favorites', 'isLoading'], true);

View File

@@ -86,7 +86,6 @@ const initialState = ImmutableMap({
blocks: ImmutableMap(),
mutes: ImmutableMap(),
chat_blocks: ImmutableMap(),
chat_mutes: ImmutableMap(),
groups: ImmutableMap(),
group_removed_accounts: ImmutableMap(),
group_join_requests: ImmutableMap(),