Skip to content

Commit

Permalink
add reducer creator for strings
Browse files Browse the repository at this point in the history
  • Loading branch information
ramantehlan committed Dec 14, 2020
1 parent 5de4f9e commit 40c6db8
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 86 deletions.
53 changes: 40 additions & 13 deletions applications/web/redux/actions.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,59 @@
//
// Action Types
//
export const TOGGLE_BINDER_MENU = "TOGGLE_BINDER_MENU"
export const TOGGLE_CONSOLE = "TOGGLE_CONSOLE"
export const TOGGLE_SAVE_DIALOG = "TOGGLE_SAVE_DIALOG"
export const BINDER_MENU = "TOGGLE_BINDER_MENU"
export const CONSOLE = "TOGGLE_CONSOLE"
export const SAVE_DIALOG = "TOGGLE_SAVE_DIALOG"

export const FILE_PATH = "FILE_PATH"
export const FILE_CONTENT = "FILE_PATH"
export const FILE_PATH = "UPDATE_FILE_PATH"
export const FILE_CONTENT = "UPDATE_FILE_PATH"
export const PROVIDER = "UPDATE_PROVIDER"
export const ORG = "UPDATE_ORG"
export const REPO = "UPDATE_REPO"
export const GIT_REF = "UPDATE_GIT_REF"

export const PROVIDER = "PROVIDER"
export const ORG = "ORG"
export const REPO = "REPO"
export const GIT_REF = "GIT_REF"
export const LANG = "LANG"
export const LANG = "UPDATE_LANG"

export const COMMIT_MESSAGE = "UPDATE_COMMIT_MESSAGE"

export const STRIP_OUTPUT = "TOGGLE_STRIP_OUTPUT"
export const FILE_BUFFER = "UPDATE_FILE_BUFFER"
export const SAVED_TIME = "UPDATE_SAVED_TIME"

export const CONSOLE_LOG = "UPDATE_CONSOLE_LOG"
export const NOTIFICATION_LOG = "UPDATE_NOTIFICATION_LOG"

export const SERVER_STATUS = "UPDATE_SERVER_STATUS"
export const HOST = "UPDATE_HOST"

export const LOGGED_IN = "UPDATE_LOGGED_IN"
export const USERNAME = "UPDATE_USERNAME"
export const USER_IMAGE = "UPDATE_IMAGE"
export const USER_LINK = "UPDATE_LINK"
//
// ACTION CREATOR
//

export const toggleStripOutput = (text: string) => ({
type: STRIP_OUTPUT,
value: text
})

export const setCommitMessage = (text: string) => ({
type: COMMIT_MESSAGE,
value: text
})

export const toggleBinderMenu = () => ({
type: TOGGLE_BINDER_MENU
type: BINDER_MENU
})

export const toggleConsole = () => ({
type: TOGGLE_CONSOLE
type: CONSOLE
})

export const toggleSaveDialog = () => ({
type: TOGGLE_SAVE_DIALOG
type: SAVE_DIALOG
})

export const setFilePath = (text: string) => ({
Expand Down
93 changes: 21 additions & 72 deletions applications/web/redux/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,20 @@ import {combineReducers} from "redux"
import * as actions from "./actions"


export const updateString = (actionName = "") => {
return (state = "", action) => {
switch (action.type){
case `UPDATE_${actionName}`:
return action.value
default:
return state
}
}
}

export const toggleBinderMenuReducer = (state = false, action) => {
switch(action.type) {
case actions.TOGGLE_BINDER_MENU:
case actions.BINDER_MENU:
return !state
default:
return state
Expand All @@ -13,7 +24,7 @@ export const toggleBinderMenuReducer = (state = false, action) => {

export const toggleConsoleReducer = (state = false, action) => {
switch(action.type) {
case actions.TOGGLE_CONSOLE:
case actions.CONSOLE:
return !state
default:
return state
Expand All @@ -22,87 +33,25 @@ export const toggleConsoleReducer = (state = false, action) => {

export const toggleSaveDialogReducer = (state = false, action) => {
switch(action.type) {
case actions.TOGGLE_SAVE_DIALOG:
case actions.SAVE_DIALOG:
return !state
default:
return state
}
}

export const filePathReducer = (state = "", action) => {
switch(action.type) {
case actions.FILE_PATH:
return action.value
default:
return state
}
}

export const fileContentReducer = (state = "", action) => {
switch(action.type) {
case actions.FILE_CONTENT:
return action.value
default:
return state
}
}

export const providerReducer = (state = "", action) => {
switch(action.type) {
case actions.PROVIDER:
return action.value
default:
return state
}
}

export const orgReducer = (state = "", action) => {
switch(action.type) {
case actions.ORG:
return action.value
default:
return state
}
}

export const repoReducer = (state = "", action) => {
switch(action.type) {
case actions.REPO:
return action.value
default:
return state
}
}

export const gitRefReducer = (state = "", action) => {
switch(action.type) {
case actions.GIT_REF:
return action.value
default:
return state
}
}

export const langReducer = (state = "", action) => {
switch(action.type) {
case actions.LANG:
return action.value
default:
return state
}
}

const globalReducer = combineReducers({
showBinderMenu: toggleBinderMenuReducer,
showConsole: toggleConsoleReducer,
showSaveDialog: toggleSaveDialogReducer,
filePath: filePathReducer,
fileContent: fileContentReducer,
provider: providerReducer,
org: orgReducer,
repo: repoReducer,
gitRef: gitRefReducer,
lang: langReducer
filePath: updateString(actions.FILE_PATH),
fileContent: updateString(actions.FILE_CONTENT),
provider: updateString(actions.PROVIDER),
org: updateString(actions.ORG),
repo: updateString(actions.REPO),
gitRef: updateString(actions.GIT_REF),
lang: updateString(actions.LANG)
})

export default globalReducer
39 changes: 38 additions & 1 deletion applications/web/redux/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,24 @@ export interface GlobalRecord {
gitRef: string,
// File info
lang: string,
// Commit Values
commitMessage: string,
// This should be a boolean value but as a string
stripOutput: boolean,
fileBuffer: object,
savedTime: object,
// Console
consoleLog: object,
notificationLog: object,
// Server
serverStatus: string,
host: object,

// Login Values
loggedIn: boolean,
username: string,
userImage: string,
userLink: string
}
export interface State extends AppState {
global: GlobalRecord,
Expand All @@ -66,7 +84,26 @@ export const initialState = Record<State>({
repo: "",
gitRef: "",
// File info
lang: ""
lang: "markdown",
// Commit Values
commitMessage: "Auto commit from nteract web",
// This should be a boolean value but as a string
stripOutput: false,
fileBuffer: {},
savedTime: new Date(),

// Console
consoleLog: [],
notificationLog: [],
// Server
serverStatus: "launching...",
host: {},

// Login Values
loggedIn: false,
username: "",
userImage: "",
userLink: ""
},
app: makeAppRecord({
version: "@nteract/web",
Expand Down

0 comments on commit 40c6db8

Please sign in to comment.