-
Notifications
You must be signed in to change notification settings - Fork 17
add-vuejs-gs-with-vuex #414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
benoitvidis
merged 19 commits into
save-vuejs-getting-started
from
add-vuejs-gs-with-vuex
Jul 10, 2019
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
b423f5f
change fixtures && environment loading
berthieresteban 869f546
add vuejs gs with vuex
berthieresteban 6b0e02a
[wip] Integrating e2e tests
xbill82 53d71ab
remove comment && rename data
berthieresteban bc972dd
Merge branch 'fix-gs-tests' of https://github.com/kuzzleio/sdk-javasc…
xbill82 43847e2
Merge branch 'merge-fixes' into fix-gs-tests
xbill82 3e9ac14
[ci] Using new test script in CI
xbill82 a41ac8e
add package-lock
berthieresteban d827819
add libgconf-2-4
berthieresteban d1f2684
[ci] Install libgconf
xbill82 ca2d2e5
[ci] fix sudo apt
xbill82 91b9eb8
[ci] Cypress record setup
xbill82 07d4e52
cypress upload on fail only
berthieresteban 302f6ae
fix send message test
berthieresteban 335e564
pull fix gs tests
berthieresteban 3f38a70
dont use yarn
Aschen 757b70c
Merge branch '6-dev' into add-vuejs-gs-with-vuex
Aschen 7565d4e
unsubscribe on destroy
berthieresteban c709691
Merge branch 'save-vuejs-getting-started' into add-vuejs-gs-with-vuex
berthieresteban File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,5 @@ | ||
module.exports = { | ||
presets: [ | ||
'@vue/app' | ||
] | ||
} |
Binary file not shown.
This file contains hidden or 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,17 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width,initial-scale=1.0"> | ||
<link rel="icon" href="<%= BASE_URL %>favicon.ico"> | ||
<title>kuzzle-vuejs-gs</title> | ||
</head> | ||
<body> | ||
<noscript> | ||
<strong>We're sorry but kuzzle-vuejs-gs doesn't work properly without JavaScript enabled. Please enable it to continue.</strong> | ||
</noscript> | ||
<div id="app"></div> | ||
<!-- built files will be auto injected --> | ||
</body> | ||
</html> |
This file contains hidden or 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,121 @@ | ||
<template> | ||
<div id="app"> | ||
<div v-if="!enteredNickname"> | ||
<input | ||
autofocus | ||
v-on:keyup.enter="valid" | ||
type="text" | ||
v-model="nicknameInput" | ||
placeholder="Enter your nickname" | ||
/> | ||
<button @click="valid">Valid</button> | ||
</div> | ||
<div class="wrapper" v-else> | ||
<input | ||
autofocus | ||
type="text" | ||
placeholder="Enter your message" | ||
v-model="message" | ||
v-on:keyup.enter="sendMessage" | ||
/> | ||
<button @click="sendMessage">Send</button> | ||
</div> | ||
<div | ||
v-for="message in messages" | ||
:key="message._id" | ||
:class="`messages ${message.username === nicknameInput? 'fromMe': 'fromOthers'}`" | ||
> | ||
<span class="nickname">{{ message.username }}</span> | ||
<span>({{ getDate(message.createdAt) }})</span> | ||
<p>{{ message.value }}</p> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import kuzzle from "./services/kuzzle"; | ||
|
||
export default { | ||
name: "app", | ||
data() { | ||
return { | ||
enteredNickname: false, | ||
nicknameInput: "", | ||
message: "" | ||
}; | ||
}, | ||
computed: { | ||
nickname() { | ||
return this.$store.state.nickname; | ||
}, | ||
messages() { | ||
return this.$store.state.messages; | ||
} | ||
}, | ||
methods: { | ||
getDate(timestamp) { | ||
const date = new Date(timestamp); | ||
return date.toString().split("GMT")[0]; | ||
}, | ||
async sendMessage() { | ||
if (this.message === "") return; | ||
await this.$store.dispatch("SEND_MESSAGE", { | ||
kuzzle, | ||
message: this.message | ||
}); | ||
this.message = ""; | ||
}, | ||
async valid() { | ||
this.$store.commit("SET_NICKNAME", this.nicknameInput); | ||
this.enteredNickname = true; | ||
await this.$store.dispatch("INIT", { kuzzle }); | ||
} | ||
}, | ||
async destroyed () { | ||
await this.$store.dispatch("UNSUBSCRIBE_MESSAGES", { kuzzle }); | ||
} | ||
}; | ||
</script> | ||
|
||
<style> | ||
#app { | ||
font-family: "Avenir", Helvetica, Arial, sans-serif; | ||
-webkit-font-smoothing: antialiased; | ||
-moz-osx-font-smoothing: grayscale; | ||
text-align: center; | ||
color: #2c3e50; | ||
margin-top: 60px; | ||
} | ||
|
||
.nickname { | ||
font-weight: bold; | ||
} | ||
|
||
.wrapper { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
margin-bottom: 10px; | ||
} | ||
|
||
.messages { | ||
padding: 10px; | ||
margin: 1px; | ||
width: 45vw; | ||
border-radius: 10px; | ||
} | ||
|
||
.fromMe { | ||
text-align: right; | ||
float: right; | ||
margin-left: 49vw; | ||
background-color: #9ca4f0; | ||
} | ||
|
||
.fromOthers { | ||
text-align: left; | ||
margin-right: 49vw; | ||
float: left; | ||
background-color: rgb(206, 246, 147); | ||
} | ||
</style> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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,9 @@ | ||
import Vue from 'vue' | ||
import App from './App.vue' | ||
import store from './store.js' | ||
Vue.config.productionTip = false | ||
|
||
new Vue({ | ||
store, | ||
render: h => h(App), | ||
}).$mount('#app') |
This file contains hidden or 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 @@ | ||
import { Kuzzle, WebSocket } from 'kuzzle-sdk'; | ||
|
||
export default new Kuzzle(new WebSocket('localhost')); |
This file contains hidden or 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,71 @@ | ||
import Vue from 'vue' | ||
import Vuex from 'vuex' | ||
|
||
Vue.use(Vuex) | ||
|
||
export default new Vuex.Store({ | ||
state: { | ||
messages: [], | ||
roomID: '', | ||
nickname: '' | ||
}, | ||
actions: { | ||
INIT: async ({ dispatch }, { kuzzle }) => { | ||
await kuzzle.connect(); | ||
if (!(await kuzzle.index.exists("chat"))) { | ||
await kuzzle.index.create("chat"); | ||
await kuzzle.collection.create("chat", "messages"); | ||
} | ||
dispatch('FETCH_MESSAGES', {kuzzle}); | ||
}, | ||
SEND_MESSAGE: async ({ state }, { kuzzle, message }) => { | ||
await kuzzle.document.create("chat", "messages", { | ||
value: message, | ||
username: state.nickname | ||
}); | ||
}, | ||
FETCH_MESSAGES: async ({ commit, dispatch }, { kuzzle }) => { | ||
const results = await kuzzle.document.search( | ||
"chat", | ||
"messages", | ||
{ sort: ["_kuzzle_info.createdAt"] }, | ||
{ size: 100 } | ||
); | ||
results.hits.map(hit => { | ||
commit('ADD_MESSAGE', hit); | ||
}); | ||
dispatch('SUBSCRIBE_MESSAGES', {kuzzle}); | ||
}, | ||
SUBSCRIBE_MESSAGES: async ({ commit }, { kuzzle }) => { | ||
const roomID = await kuzzle.realtime.subscribe("chat", "messages", {}, notification => { | ||
if ( | ||
notification.type === "document" && | ||
notification.action === "create" | ||
) { | ||
commit('ADD_MESSAGE', notification.result); | ||
} | ||
}); | ||
commit('SET_ROOMID', roomID); | ||
}, | ||
UNSUBSCRIBE_MESSAGES: async ({ state }, { kuzzle }) => { | ||
await kuzzle.realtime.unsubscribe(state.roomID); | ||
} | ||
}, | ||
mutations: { | ||
ADD_MESSAGE(state, hit) { | ||
const message = { | ||
_id: hit._id, | ||
value: hit._source.value, | ||
createdAt: hit._source._kuzzle_info.createdAt, | ||
username: hit._source.username | ||
}; | ||
state.messages = [message, ...state.messages] | ||
}, | ||
SET_ROOMID(state, roomID) { | ||
state.roomID = roomID; | ||
}, | ||
SET_NICKNAME(state, nickname) { | ||
state.nicnkame = nickname; | ||
} | ||
} | ||
}) |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You set the roomId in the store but you never use it. I think you should unsubscribe this roomId at some point (when the route change for example)
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Effectively, I did this in the other vuejs gettings-started at line 103, and i explained why I set the roomId in comments because in this little app I don't think its better to weighing the router.
Should I change that in both vuejs getting-started ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm just worried people would not understand why we do this in the getting started so I think it would be better, yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay I'll do the changes :)