-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from rokumatsumoto/like-design
Add like button to the design page
- Loading branch information
Showing
45 changed files
with
507 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,11 @@ | |
} | ||
} | ||
|
||
.btn-grayish-navy { | ||
color: $white; | ||
background-color: #525f7f; | ||
} | ||
|
||
.no-outline { | ||
|
||
&:focus, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<script> | ||
import { mapActions, mapState } from 'vuex'; | ||
export default { | ||
name: 'LikeButton', | ||
props: { | ||
likeCssClass: { | ||
type: String, | ||
required: true, | ||
}, | ||
unlikeCssClass: { | ||
type: String, | ||
required: true, | ||
}, | ||
likeText: { | ||
type: String, | ||
required: true, | ||
}, | ||
unlikeText: { | ||
type: String, | ||
required: true, | ||
}, | ||
likedStatus: { | ||
type: Boolean, | ||
required: true, | ||
}, | ||
endpoint: { | ||
type: String, | ||
required: true, | ||
}, | ||
}, | ||
computed: { | ||
...mapState(['liked']), | ||
buttonText() { | ||
return this.liked ? this.unlikeText : this.likeText; | ||
}, | ||
buttonCssClass() { | ||
return this.liked ? this.unlikeCssClass : this.likeCssClass; | ||
}, | ||
}, | ||
created() { | ||
this.setLiked(this.likedStatus); | ||
}, | ||
methods: { | ||
...mapActions(['createNewLike', 'deleteLike', 'setLiked']), | ||
actionButtonClicked() { | ||
if (this.liked) { | ||
return this.deleteLike({ endpoint: this.endpoint }); | ||
} | ||
return this.createNewLike({ endpoint: this.endpoint }); | ||
}, | ||
}, | ||
}; | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<button :class="buttonCssClass" @click="actionButtonClicked"> | ||
<span> | ||
<i class="fas fa-lg fa-heart"></i> | ||
</span> | ||
<span class="btn-inner--text">{{ buttonText }}</span> | ||
</button> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import axios from 'lib/utils/axios_utils'; | ||
import eventHub from 'page_counters/components/event_hub'; | ||
import * as types from './mutation_types'; | ||
|
||
export const setLiked = ({ commit }, liked) => commit(types.SET_LIKED, liked); | ||
|
||
export const receiveDeleteLikeError = ({ dispatch }, payload) => { | ||
// TODO: post error | ||
}; | ||
|
||
export const receiveDeleteLike = ({ dispatch }) => { | ||
dispatch('setLiked', false); | ||
|
||
eventHub.$emit('unlike'); | ||
}; | ||
|
||
export const deleteLike = ({ dispatch }, payload) => { | ||
axios | ||
.delete(payload.endpoint) | ||
.then(response => { | ||
dispatch('receiveDeleteLike'); | ||
}) | ||
.catch(error => { | ||
const errorPayload = Object.assign(payload, { error }); | ||
dispatch('receiveDeleteLikeError', errorPayload); | ||
}); | ||
}; | ||
|
||
export const receiveCreateLikeError = ({ dispatch }, payload) => { | ||
// TODO: post error | ||
}; | ||
|
||
export const receiveCreateLike = ({ dispatch }) => { | ||
dispatch('setLiked', true); | ||
|
||
eventHub.$emit('like'); | ||
}; | ||
|
||
export const createNewLike = ({ dispatch }, payload) => { | ||
axios | ||
.post(payload.endpoint) | ||
.then(response => { | ||
dispatch('receiveCreateLike'); | ||
}) | ||
.catch(error => { | ||
const errorPayload = Object.assign(payload, { error }); | ||
dispatch('receiveCreateLikeError', errorPayload); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import Vue from 'vue/dist/vue.esm'; | ||
import Vuex from 'vuex'; | ||
import * as actions from './actions'; | ||
import mutations from './mutations'; | ||
import state from './state'; | ||
|
||
Vue.use(Vuex); | ||
|
||
export default function createStore() { | ||
return new Vuex.Store({ | ||
actions, | ||
mutations, | ||
state: state(), | ||
strict: process.env.NODE_ENV !== 'production', | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const SET_LIKED = 'SET_LIKED'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import * as types from './mutation_types'; | ||
|
||
export default { | ||
[types.SET_LIKED](state, liked) { | ||
Object.assign(state, { liked }); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default () => ({ | ||
liked: false, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<script> | ||
import counterMixin from 'page_counters/mixins/counter_mixin'; | ||
import { mapActions } from 'vuex'; | ||
import eventHub from './event_hub'; | ||
export default { | ||
name: 'LikesCounter', | ||
mixins: [counterMixin], | ||
created() { | ||
eventHub.$on('like', this.incrementCounter); | ||
eventHub.$on('unlike', this.decrementCounter); | ||
}, | ||
beforeDestroy() { | ||
eventHub.$off('like', this.incrementCounter); | ||
eventHub.$off('unlike', this.decrementCounter); | ||
}, | ||
methods: { | ||
...mapActions(['setLikesCount']), | ||
incrementCounter() { | ||
let likesCount = this.count; | ||
this.setLikesCount((likesCount += 1)); | ||
}, | ||
decrementCounter() { | ||
let likesCount = this.count; | ||
this.setLikesCount((likesCount -= 1)); | ||
}, | ||
}, | ||
}; | ||
</script> | ||
<template> | ||
<span v-if="showCounter" data-toggle="tooltip" data-placement="bottom" :title="counterTooltip"> | ||
<i class="fas fa-heart mr-1"></i> | ||
{{ localeCount }} | ||
</span> | ||
</template> |
Oops, something went wrong.