Skip to content
This repository has been archived by the owner on Jul 7, 2020. It is now read-only.

Add realtime update feature. #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/notes/components/Notes.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import { JS } from 'fsts'

import AmplifyStore from '../../store/store'

import { CreateTodo, ListTodos, UpdateTodo, DeleteTodo } from './persist/graphqlActions';
import { CreateTodo, ListTodos, UpdateTodo, DeleteTodo, onCreateTodo, onUpdateTodo, onDeleteTodo } from './persist/graphqlActions';

import NotesTheme from '../NotesTheme'
import Note from './Note'
Expand All @@ -67,6 +67,24 @@ export default {
created() {
this.logger = new this.$Amplify.Logger('NOTES_component')
this.list();
this.$Amplify.API.graphql(this.$Amplify.graphqlOperation(onCreateTodo)).subscribe({
next: (data) => {
console.log(data);
this.list();
}
});
this.$Amplify.API.graphql(this.$Amplify.graphqlOperation(onUpdateTodo)).subscribe({
next: (data) => {
console.log(data);
this.list();
}
});
this.$Amplify.API.graphql(this.$Amplify.graphqlOperation(onDeleteTodo)).subscribe({
next: (data) => {
console.log(data);
this.list();
}
});
},
computed: {
userId: function() { return AmplifyStore.state.userId }
Expand Down
36 changes: 34 additions & 2 deletions src/notes/components/persist/graphqlActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,43 @@ const DeleteTodo = `mutation DeleteTodo($id: ID!) {
id
}
}
`
`;

const onCreateTodo = /* GraphQL */ `
subscription OnCreateTodo {
onCreateTodo {
id
note
done
}
}
`;
const onUpdateTodo = /* GraphQL */ `
subscription OnUpdateTodo {
onUpdateTodo {
id
note
done
}
}
`;
const onDeleteTodo = /* GraphQL */ `
subscription OnDeleteTodo {
onDeleteTodo {
id
note
done
}
}
`;


export {
CreateTodo,
ListTodos,
UpdateTodo,
DeleteTodo
DeleteTodo,
onCreateTodo,
onUpdateTodo,
onDeleteTodo,
}