Skip to content

FSA-ify Git and Notification #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 22 additions & 23 deletions app/components/Git/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@ import { notify, NOTIFY_TYPE } from '../Notification/actions'
import { showModal, dismissModal } from '../Modal/actions'

export const GIT_STATUS = 'GIT_STATUS'
export function updateStatus ({files, isClean}) {
export function updateStatus (payload) {
return {
type: GIT_STATUS,
files,
isClean
payload
}
}

export const GIT_UPDATE_COMMIT_MESSAGE = 'GIT_UPDATE_COMMIT_MESSAGE'
export function updateCommitMessage (commitMessage) {
export function updateCommitMessage (payload) {
return {
type: GIT_UPDATE_COMMIT_MESSAGE,
commitMessage
payload
}
}

Expand All @@ -28,18 +27,18 @@ export function commit ({files, commitMessage: message}) {
}

export const GIT_STAGE_FILE = 'GIT_STAGE_FILE'
export function stageFile (file) {
export function stageFile (payload) {
return {
type: GIT_STAGE_FILE,
fileName: file.name
payload
}
}

export const GIT_UNSTAGE_FILE = 'GIT_UNSTAGE_FILE'
export function unstageFile (file) {
export function unstageFile (payload) {
return {
type: GIT_UNSTAGE_FILE,
fileName: file.name
payload
}
}

Expand All @@ -57,7 +56,7 @@ export function getBranches () {
api.gitBranch().then(data => {
dispatch({
type: GIT_BRANCH,
branches: data
payload: { branches: data }
})
})
}
Expand Down Expand Up @@ -99,15 +98,15 @@ export const GIT_CURRENT_BRANCH = 'GIT_CURRENT_BRANCH'
export function updateCurrentBranch ({ name }) {
return {
type: GIT_CURRENT_BRANCH,
branch: name,
payload: {branch: name},
}
}

export const GIT_UPDATE_STASH_MESSAGE = 'GIT_UPDATE_STASH_MESSAGE'
export function updateStashMessage (stashMessage) {
export function updateStashMessage (payload) {
return {
type: GIT_UPDATE_STASH_MESSAGE,
stashMessage,
payload,
}
}

Expand All @@ -127,34 +126,34 @@ export function createStash (message) {
}

export const GIT_UPDATE_STASH_LIST = 'GIT_UPDATE_STASH_LIST'
export function updateStashList (stashList) {
export function updateStashList (payload) {
return {
type: GIT_UPDATE_STASH_LIST,
stashList: stashList
payload
}
}

export const GIT_UPDATE_UNSTASH_IS_POP = 'GIT_UPDATE_UNSTASH_IS_POP'
export function updateUnstashIsPop (isPop) {
export function updateUnstashIsPop (payload) {
return {
type: GIT_UPDATE_UNSTASH_IS_POP,
isPop
payload
}
}

export const GIT_UPDATE_UNSTASH_IS_REINSTATE = 'GIT_UPDATE_UNSTASH_IS_REINSTATE'
export function updateUnstashIsReinstate (isReinstate) {
export function updateUnstashIsReinstate (payload) {
return {
type: GIT_UPDATE_UNSTASH_IS_REINSTATE,
isReinstate
payload
}
}

export const GIT_UPDATE_UNSTASH_BRANCH_NAME = 'GIT_UPDATE_UNSTASH_BRANCH_NAME'
export function updateUnstashBranchName (newBranchName) {
export function updateUnstashBranchName (payload) {
return {
type: GIT_UPDATE_UNSTASH_BRANCH_NAME,
newBranchName
payload
}
}

Expand All @@ -165,10 +164,10 @@ export function getStashList () {
}

export const GIT_SELECT_STASH = 'GIT_SELECT_STASH'
export function selectStash (selectedStash) {
export function selectStash (payload) {
return {
type: GIT_SELECT_STASH,
selectedStash: selectedStash
payload
}
}

Expand Down
32 changes: 14 additions & 18 deletions app/components/Git/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,68 +46,64 @@ export default function GitReducer (state = _state, action) {
switch (action.type) {

case GIT_STATUS:
var workingDirDelta = {
isClean: action.isClean,
files: action.files
}
state.workingDir = Object.assign({}, state.workingDir, workingDirDelta)
state.workingDir = Object.assign({}, state.workingDir, action.payload)
return state

case GIT_UPDATE_COMMIT_MESSAGE:
state.stagingArea.commitMessage = action.commitMessage
state.stagingArea.commitMessage = action.payload
return state

case GIT_STAGE_FILE:
state.stagingArea.files = _.union(state.stagingArea.files, [action.fileName])
state.stagingArea.files = _.union(state.stagingArea.files, [action.payload.name])
return state

case GIT_UNSTAGE_FILE:
state.stagingArea.files = _.without(state.stagingArea.files, action.fileName)
state.stagingArea.files = _.without(state.stagingArea.files, action.payload.name)
return state

case GIT_BRANCH:
state.branches = action.branches
state.branches = action.payload.branches
return state

case GIT_CHECKOUT:
state.branches.current = action.branch
return state

case GIT_CURRENT_BRANCH:
state.branches.current = action.branch
state.branches.current = action.payload.branch
return state

case GIT_UPDATE_STASH_MESSAGE:
state.stash.stashMessage = action.stashMessage
state.stash.stashMessage = action.payload
return state

case GIT_UPDATE_UNSTASH_IS_POP:
state.unstash.isPop = action.isPop
state.unstash.isPop = action.payload
return state

case GIT_UPDATE_UNSTASH_IS_POP:
state.unstash.isPop = action.isPop
return state

case GIT_UPDATE_UNSTASH_IS_REINSTATE:
state.unstash.isReinstate = action.isReinstate
state.unstash.isReinstate = action.payload
return state

case GIT_UPDATE_UNSTASH_BRANCH_NAME:
state.unstash.newBranchName = action.newBranchName
state.unstash.newBranchName = action.payload
return state

case GIT_UPDATE_STASH_LIST:
state.unstash.stashList = action.stashList
if (action.stashList.length == 0) {
state.unstash.stashList = action.payload
if (state.unstash.stashList.length == 0) {
state.unstash.selectedStash = null
} else if(!state.unstash.selectedStash) {
state.unstash.selectedStash = action.stashList[0]
state.unstash.selectedStash = state.unstash.stashList[0]
}
return state

case GIT_SELECT_STASH:
state.unstash.selectedStash = action.selectedStash
state.unstash.selectedStash = action.payload
return state

default:
Expand Down
12 changes: 6 additions & 6 deletions app/components/Notification/actions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* @flow weak */
export const NOTIFICATION_ADD = 'NOTIFICATION_ADD'
export function addNotification (_notification) {
export function addNotification (payload) {
return dispatch => {
var notification, defaultNotification

Expand All @@ -12,19 +12,19 @@ export function addNotification (_notification) {
onClick: () => dispatch({type: NOTIFICATION_REMOVE, notification})
}

let { notifyType } = _notification
let { notifyType } = payload
if (notifyType === NOTIFY_TYPE.ERROR) {
defaultNotification = {...defaultNotification, ...{
barStyle: { backgroundColor:'red' },
actionStyle: { color:'white' }
}}
}

notification = {...defaultNotification, ..._notification}
payload = {...defaultNotification, ...payload}

dispatch({
type: NOTIFICATION_ADD,
notification
payload
})
}
}
Expand All @@ -37,9 +37,9 @@ export const NOTIFY_TYPE = {
}

export const NOTIFICATION_REMOVE = 'NOTIFICATION_REMOVE'
export function removeNotification (notification) {
export function removeNotification (payload) {
return {
type: NOTIFICATION_REMOVE,
notification
payload
}
}
4 changes: 2 additions & 2 deletions app/components/Notification/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ export default function NotificationReducer (state = {notifications: []}, action

switch (action.type) {
case NOTIFICATION_ADD:
state.notifications.push(action.notification)
state.notifications.push(action.payload)
return state

case NOTIFICATION_REMOVE:
_.remove(state.notifications, action.notification)
_.remove(state.notifications, action.payload)
return state

default:
Expand Down