1
0
mirror of https://github.com/tooot-app/app synced 2025-06-05 22:19:13 +02:00

Rewrite upload media

This commit is contained in:
Zhiyuan Zheng
2020-12-30 00:56:25 +01:00
parent e841409523
commit 3473337442
23 changed files with 1136 additions and 1108 deletions

View File

@ -0,0 +1,77 @@
import { ComposeAction, ComposeState } from "./types"
const composeReducer = (
state: ComposeState,
action: ComposeAction
): ComposeState => {
switch (action.type) {
case 'spoiler':
return { ...state, spoiler: { ...state.spoiler, ...action.payload } }
case 'text':
return { ...state, text: { ...state.text, ...action.payload } }
case 'tag':
return { ...state, tag: action.payload }
case 'emoji':
return { ...state, emoji: action.payload }
case 'poll':
return { ...state, poll: { ...state.poll, ...action.payload } }
case 'attachments/sensitive':
return {
...state,
attachments: { ...state.attachments, ...action.payload }
}
case 'attachment/upload/start':
return {
...state,
attachments: {
...state.attachments,
uploads: state.attachments.uploads.concat([action.payload])
}
}
case 'attachment/upload/end':
return {
...state,
attachments: {
...state.attachments,
uploads: state.attachments.uploads.map(upload =>
upload.local?.uri === action.payload.local?.uri
? { ...upload, remote: action.payload.remote, uploading: false }
: upload
)
}
}
case 'attachment/delete':
return {
...state,
attachments: {
...state.attachments,
uploads: state.attachments.uploads.filter(
upload => upload.remote!.id !== action.payload
)
}
}
case 'attachment/edit':
return {
...state,
attachments: {
...state.attachments,
uploads: state.attachments.uploads.map(upload =>
upload.remote!.id === action.payload!.id
? { ...upload, remote: action.payload }
: upload
)
}
}
case 'visibility':
return { ...state, visibility: action.payload }
case 'textInputFocus':
return {
...state,
textInputFocus: { ...state.textInputFocus, ...action.payload }
}
default:
throw new Error('Unexpected action')
}
}
export default composeReducer