Progress
This commit is contained in:
62
app/javascript/gabsocial/reducers/albums.js
Normal file
62
app/javascript/gabsocial/reducers/albums.js
Normal file
@@ -0,0 +1,62 @@
|
||||
import {
|
||||
BOOKMARK_COLLECTIONS_FETCH_REQUEST,
|
||||
BOOKMARK_COLLECTIONS_FETCH_SUCCESS,
|
||||
BOOKMARK_COLLECTIONS_FETCH_FAIL,
|
||||
} from '../actions/bookmarks'
|
||||
import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable'
|
||||
|
||||
const initialState = ImmutableMap({
|
||||
items: ImmutableList(),
|
||||
isLoading: false,
|
||||
isFetched: false,
|
||||
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:
|
||||
return state.withMutations((map) => {
|
||||
map.set('isLoading', true)
|
||||
map.set('isFetched', false)
|
||||
map.set('isError', false)
|
||||
})
|
||||
case SHORTCUTS_FETCH_SUCCESS:
|
||||
return state.withMutations((map) => {
|
||||
map.set('items', normalizeShortcuts(action.shortcuts))
|
||||
map.set('isLoading', false)
|
||||
map.set('isFetched', true)
|
||||
map.set('isError', false)
|
||||
})
|
||||
case SHORTCUTS_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:
|
||||
return state.update('items', list => list.filterNot((item) => {
|
||||
return `${item.get('id')}` === `${action.shortcutId}`
|
||||
}))
|
||||
default:
|
||||
return state
|
||||
}
|
||||
}
|
||||
62
app/javascript/gabsocial/reducers/bookmark_collections.js
Normal file
62
app/javascript/gabsocial/reducers/bookmark_collections.js
Normal file
@@ -0,0 +1,62 @@
|
||||
import {
|
||||
BOOKMARK_COLLECTIONS_FETCH_REQUEST,
|
||||
BOOKMARK_COLLECTIONS_FETCH_SUCCESS,
|
||||
BOOKMARK_COLLECTIONS_FETCH_FAIL,
|
||||
} from '../actions/bookmarks'
|
||||
import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable'
|
||||
|
||||
const initialState = ImmutableMap({
|
||||
items: ImmutableList(),
|
||||
isLoading: false,
|
||||
isFetched: false,
|
||||
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:
|
||||
return state.withMutations((map) => {
|
||||
map.set('isLoading', true)
|
||||
map.set('isFetched', false)
|
||||
map.set('isError', false)
|
||||
})
|
||||
case SHORTCUTS_FETCH_SUCCESS:
|
||||
return state.withMutations((map) => {
|
||||
map.set('items', normalizeShortcuts(action.shortcuts))
|
||||
map.set('isLoading', false)
|
||||
map.set('isFetched', true)
|
||||
map.set('isError', false)
|
||||
})
|
||||
case SHORTCUTS_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:
|
||||
return state.update('items', list => list.filterNot((item) => {
|
||||
return `${item.get('id')}` === `${action.shortcutId}`
|
||||
}))
|
||||
default:
|
||||
return state
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import { me } from '../initial_state'
|
||||
import {
|
||||
CHAT_MESSAGES_SEND_SUCCESS,
|
||||
CHAT_MESSAGES_DELETE_REQUEST,
|
||||
CHAT_MESSAGES_PURGE_REQUEST,
|
||||
} from '../actions/chat_messages'
|
||||
import {
|
||||
CHAT_CONVERSATIONS_APPROVED_FETCH_SUCCESS,
|
||||
@@ -14,6 +15,7 @@ import {
|
||||
CHAT_CONVERSATIONS_REQUESTED_FETCH_SUCCESS,
|
||||
CHAT_CONVERSATIONS_REQUESTED_EXPAND_SUCCESS,
|
||||
CHAT_CONVERSATION_REQUEST_APPROVE_SUCCESS,
|
||||
CHAT_CONVERSATION_MARK_READ_SUCCESS,
|
||||
} from '../actions/chat_conversations'
|
||||
|
||||
const initialState = ImmutableMap()
|
||||
@@ -50,6 +52,11 @@ export default function chat_conversations(state = initialState, action) {
|
||||
case CHAT_MESSAGES_DELETE_REQUEST:
|
||||
// : todo : set last conversation message to one prior to this one
|
||||
return state
|
||||
case CHAT_MESSAGES_PURGE_REQUEST:
|
||||
// : todo :
|
||||
return state
|
||||
case CHAT_CONVERSATION_MARK_READ_SUCCESS:
|
||||
return importChatConversation(state, action.chatConversation)
|
||||
default:
|
||||
return state
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { Map as ImmutableMap, fromJS } from 'immutable'
|
||||
import {
|
||||
CHAT_MESSAGES_SEND_SUCCESS,
|
||||
CHAT_MESSAGES_DELETE_REQUEST,
|
||||
CHAT_MESSAGES_PURGE_REQUEST,
|
||||
} from '../actions/chat_messages'
|
||||
import {
|
||||
CHAT_MESSAGES_IMPORT,
|
||||
@@ -26,6 +27,8 @@ export default function chat_messages(state = initialState, action) {
|
||||
return importChatMessage(state, action.chatMessage)
|
||||
case CHAT_MESSAGES_DELETE_REQUEST:
|
||||
return deleteChatMessage(state, action.chatMessageId)
|
||||
case CHAT_MESSAGES_PURGE_REQUEST:
|
||||
return state
|
||||
default:
|
||||
return state
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
import {
|
||||
CHAT_CONVERSATION_APPROVED_UNREAD_COUNT_FETCH_SUCCESS,
|
||||
CHAT_CONVERSATION_REQUESTED_COUNT_FETCH_SUCCESS,
|
||||
CHAT_CONVERSATION_MARK_READ_FETCH,
|
||||
} from '../actions/chat_conversations'
|
||||
import {
|
||||
CHAT_MESSAGES_FETCH_SUCCESS,
|
||||
@@ -34,6 +35,10 @@ export default function chats(state = initialState, action) {
|
||||
return state.set('chatConversationRequestCount', action.count)
|
||||
case CHAT_CONVERSATION_APPROVED_UNREAD_COUNT_FETCH_SUCCESS:
|
||||
return state.set('chatsUnreadCount', action.count)
|
||||
case CHAT_CONVERSATION_MARK_READ_FETCH:
|
||||
const chatConversationUnreadCount = action.chatConversation.get('unread_count')
|
||||
const totalUnreadCount = state.get('chatsUnreadCount')
|
||||
return state.set('chatsUnreadCount', Math.max(totalUnreadCount - chatConversationUnreadCount, 0))
|
||||
default:
|
||||
return state
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user