Skip to content

Commit

Permalink
Merge for user boards
Browse files Browse the repository at this point in the history
  • Loading branch information
csliva committed Jan 22, 2018
1 parent 130ae69 commit e87f6fb
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ defmodule Stracker.Repo.Migrations.CreateStack do
create table(:stacks) do
add :stack_title, :string
add :description, :string
add :created_by, :string
add :latest_contributor, :string
add :board_id, references(:boards, on_delete: :nothing), null: false
timestamps()
end

Expand Down
4 changes: 2 additions & 2 deletions api/web/controllers/api/stack_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ defmodule Stracker.StackController do
render(conn, "show.json", stack: stack)
end

def get_by_user(conn, %{"users" => users}) do
def get_by_board(conn, %{"board_id" => board_id}) do
stacks = Repo.all(
from p in Stack,
select: p,
where: ^users == p.users,
where: ^board_id == p.board_id,
order_by: [desc: p.updated_at]
)
render(conn, "index.json", stacks: stacks)
Expand Down
5 changes: 1 addition & 4 deletions api/web/models/stack.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ defmodule Stracker.Stack do
@primary_key {:id, autogenerate: true}
field :stack_title, :string
field :description, :string
field :created_by, :string
field :latest_contributor, :string
belongs_to :user, Stracker.User
belongs_to :board, Stracker.Board
timestamps()
end
Expand All @@ -17,7 +14,7 @@ defmodule Stracker.Stack do
"""
def changeset(struct, params \\ %{}) do
struct
|> cast(params, [:stack_title, :description, :user, :board])
|> cast(params, [:stack_title, :description, :board_id])
|> validate_required([:stack_title])
end
end
2 changes: 1 addition & 1 deletion api/web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ defmodule Stracker.Router do
pipe_through :api
resources "/users", UserController, except: [:new, :edit]
resources "/stacks", StackController
get "/stacks/user/:user_id", StackController, :get_by_user
get "/stacks/board/:board_id", StackController, :get_by_board
post "/sessions", SessionController, :create
delete "/sessions", SessionController, :delete
post "/sessions/refresh", SessionController, :refresh
Expand Down
1 change: 0 additions & 1 deletion api/web/views/stack_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ defmodule Stracker.StackView do
%{id: stack.id,
stack_title: stack.stack_title,
description: stack.description,
user_id: stack.user_id
}
end
end
17 changes: 6 additions & 11 deletions web/src/actions/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ export function editStack(data) {
}

export function newStack(data) {
console.log(data)
return dispatch => api.post('/stacks', data)
.then((response) => {
dispatch(reset('newStack'));
updateStacks(response.data.user_id, dispatch);
updateActiveStack(response, dispatch);
//updateStacks(response.data.user_id, dispatch);
//updateActiveStack(response, dispatch);
});
}

Expand All @@ -75,7 +76,7 @@ function updateActiveStack(response, dispatch) {
function updateStacks(currentUserId, dispatch) {
console.log("Getting all stacks for " + currentUserId);
dispatch({ type: 'GET_STACKS_REQUEST' });
return api.fetch(`/stacks/user/${currentUserId}`)
return api.fetch(`/stacks/board/${currentUserId}`)
.then((response) => {
dispatch({type: 'RECIEVE_ALL_STACKS', response})
})
Expand All @@ -88,9 +89,9 @@ function updateStacks(currentUserId, dispatch) {
// event should fire on app load, and when a new stack has been created
export function getAllStacks(currentUserId) {
console.log("Getting all stacks for " + currentUserId);
return (dispatch) => {
return (dispatch, getState) => {
dispatch({ type: 'GET_STACKS_REQUEST' });
return api.fetch(`/stacks/user/${currentUserId}`)
return api.fetch(`/stacks/board/${getState().boards.active}`)
.then((response) => {
dispatch({type: 'RECIEVE_ALL_STACKS', response})
})
Expand All @@ -99,9 +100,3 @@ export function getAllStacks(currentUserId) {
});
};
}

export function count(){
return (dispatch) => {
dispatch({ type: "COUNT_UP"});
}
}
9 changes: 5 additions & 4 deletions web/src/actions/boards.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ export function fetchBoards() {
});
}

export function setActiveBoard(response, dispatch, router) {
export function setActiveBoard(response, router) {
localStorage.setItem('board', JSON.stringify(response));
return (dispatch) => {
dispatch({ type: 'SET_ACTIVE_BOARD', response });
router.transitionTo('/');
router.transitionTo('/app');
};
}

Expand All @@ -38,14 +39,14 @@ export function createBoard(data, router) {
.then((response) => {
dispatch({ type: 'CREATE_BOARD_SUCCESS', response });
dispatch(reset('newBoard'));
//router.transitionTo(`/r/${response.data.id}`);
router.transitionTo(`/app`);
});
}

export function joinBoard(boardId, router) {
return dispatch => api.post(`/boards/${boardId}/join`)
.then((response) => {
dispatch({ type: 'BOARD_JOINED', response });
router.transitionTo(`/r/${response.data.id}`);
router.transitionTo(`/app`);
});
}
2 changes: 1 addition & 1 deletion web/src/actions/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function setCurrentUser(dispatch, response) {
dispatch({ type: 'GET_STACKS_REQUEST' });
dispatch(fetchUserBoards(response.data.id)); // new line
console.log(response.data.id)
api.fetch(`/stacks/user/${response.data.id}`)
api.fetch(`/stacks/board/${response.data.id}`)
.then((response) => {
dispatch({type: 'RECIEVE_ALL_STACKS', response})
})
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/StackDetails/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class StackDetails extends Component {
</div>
</div>
<h3 style={{ marginBottom: '2rem', textAlign: 'center' }}>{currentStack.stack_title}</h3>
<div style={{ textAlign: 'center' }}>{currentStack.notes}</div>
<div style={{ textAlign: 'center' }}>{currentStack.description}</div>
</div>
);
}
Expand Down
6 changes: 3 additions & 3 deletions web/src/components/StackForm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ class StackForm extends Component {
<form
onSubmit={handleSubmit(this.handleSubmit)}
>
<h3 className="title" style={{ marginBottom: '2rem', textAlign: 'center' }}>New Stack</h3>
<Field name="stack_title" type="text" component={Input} placeholder="Stack Title" />
<Field name="description" type="text" component={Input} placeholder="Stack Description" />
<h3 className="title" style={{ marginBottom: '2rem', textAlign: 'center' }}>Create a Task</h3>
<Field name="stack_title" type="text" component={Input} placeholder="Task Title" />
<Field name="description" type="text" component={Input} placeholder="Task Description" />
<button
type="submit"
disabled={submitting}
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/StackList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class StackList extends Component {
<div className={`column is-one-third`}>
<ul className={`${css(styles.stacklist)}`}>
{this.props.stacks.data.map(function(object, i){
return <Stack name={object.post_title} key={i} id={object.id} />;
return <Stack name={object.stack_title} key={i} id={object.id} />;
})}
</ul>
</div>
Expand Down
4 changes: 2 additions & 2 deletions web/src/components/StackView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import StackDetails from '../../components/StackDetails';
class StackView extends Component {

handleNewStack= data => {
data.lastest_contributor = this.props.currentUser.id;
console.log(data);
data.board_id = localStorage.board;
this.props.newStack(data);
}

Expand Down Expand Up @@ -50,6 +49,7 @@ export default connect(
editActive: state.stack.editActive,
currentUser: state.session.currentUser,
currentStack: state.stack.currentStack,
currentBoard: state.boards.activeBoard
}),
{ formActivate, newStack, editStack, setActiveStack }
)(StackView);
1 change: 0 additions & 1 deletion web/src/reducers/boards.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const initialState = {
};

export default function (state = initialState, action) {
console.log(action)
switch (action.type) {
case 'FETCH_BOARDS_SUCCESS':
return {
Expand Down

0 comments on commit e87f6fb

Please sign in to comment.