Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
export const sortColumn = column => {
return dispatch => {
return dispatch({
type: "SORT_COLUMN",
...column
});
};
};
export const sortProjects = column => {
// I need column to have been affected by sortColumn
return dispatch => {
const sortBy = `${column.id}_${colum.sort}`;
return dispatch({
type: "SORT_PROJECTS",
sortBy
});
};
};
onSort(column) {
return () => {
store.dispatch(sortColumn(column));
// The problem I have is that `column` is still the same column from the argument.
So I need to dispatch sortColumn and then sortProject given I can pass along the column from sortColumn to sortProject
store.dispatch(sortProject(column));
};
}
// I use sort as a way to say sort projects by name_acs given action.sortBy was set
const sort = (state = "", action) => {
switch (action.type) {
case "SORT_PROJECTS":
return action.sortBy;
default:
return state;
}
};
const table = (state = {}, action) => {
switch (action.type) {
case "SORT_COLUMN":
return { ...state, columns: columns(state.columns, action) };
default:
return state;
}
};
const columns = (state = [], action) => {
switch (action.type) {
case "SORT_COLUMN":
return state.map(c => column(c, action));
default:
return state;
}
};
const column = (state = {}, action) => {
switch (action.type) {
case "SORT_COLUMN":
return state.id !== action.id
? {
...state,
sort: false
}
: {
...state,
sort: toggleColumnSort(state)
};
default:
return state;
}
};
const toggleColumnSort = column => {
if (!column.sort || column.sort == "desc") {
return "asc";
} else {
return "desc";
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.