Skip to content

Commit

Permalink
Crear columnas
Browse files Browse the repository at this point in the history
  • Loading branch information
juanwmedia committed May 14, 2021
1 parent b274641 commit 0ae7292
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/components/ColumnList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default {
setup() {
const store = useStore();
const columns = computed({
get: () => store.state.boardModule.columns,
get: () => store.getters["boardModule/getColumns"],
set: value => store.dispatch("boardModule/updateColumns", value)
});
return { columns };
Expand Down
14 changes: 12 additions & 2 deletions src/components/NavBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
>
{{ boardName }}
</h1>
<a href="#" class="ml-2 text-sm block text-center mt-3"
<a
@click="createColumn"
href="#"
class="ml-2 text-sm block text-center mt-3"
>Create column</a
>
</div>
Expand Down Expand Up @@ -43,7 +46,14 @@ export default {
console.error(error);
}
}
return { boardName, userLogout };
async function createColumn() {
try {
await store.dispatch("boardModule/createColumn");
} catch (error) {
console.error(error.message);
}
}
return { boardName, userLogout, createColumn };
},
components: {
UserAvatar
Expand Down
36 changes: 35 additions & 1 deletion src/store/boardModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,20 @@ export default {
},
getters: {
getBoardName: state => state.board.name,
getColumns: state => state.columns.sort((a, b) => a.order - b.order),
getCardsByColumn: state => column =>
state.cards
.filter(card => card.column === column)
.sort((a, b) => a.order - b.order)
.sort((a, b) => a.order - b.order),
getNextColumnOrder: state =>
Math.max(...state.columns.map(column => column.order)) + 1
},
mutations: {
setBoard(state, board) {
state.board = board;
},
setColumns(state, columns) {
state.columns = columns;
}
},
actions: {
Expand Down Expand Up @@ -46,6 +52,34 @@ export default {

commit("setBoard", board);
},

async getColumns({ commit, rootState }) {
await db
.collection("columns")
.where("board", "==", rootState.userModule.user.uid)
.onSnapshot(doSnapshot);

function doSnapshot(querySnapshot) {
const columns = [];
querySnapshot.forEach(doc => {
columns.push(doc.data());
});
commit("setColumns", columns);
}
},

async createColumn({ rootState, state, getters }) {
const ref = db.collection("columns");
const { id } = ref.doc();
const column = {
name: "New Column",
id,
board: rootState.userModule.user.uid,
order: state.columns.length ? getters["getNextColumnOrder"] : 0
};
await ref.doc(id).set(column);
},

updateColumns(context, columns) {
console.log(columns);
},
Expand Down
1 change: 1 addition & 0 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default createStore({
actions: {
initApp({ dispatch }) {
dispatch("boardModule/getBoard");
dispatch("boardModule/getColumns");
}
},
modules: { boardModule, userModule }
Expand Down

0 comments on commit 0ae7292

Please sign in to comment.