Skip to content

Commit

Permalink
fixed some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ortexx committed Apr 6, 2018
1 parent f55d905 commit 70b554d
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 46 deletions.
1 change: 0 additions & 1 deletion app.js
Expand Up @@ -23,7 +23,6 @@ app.use(express.static(path.join(__dirname, 'public/assets')));
* {@link https://github.com/ortexx/akili-connect}
* {@link https://akilijs.com/docs/server}
*/

if(argv.render) {
app.get('/', akili.route);
app.get('/app', akili.route);
Expand Down
57 changes: 32 additions & 25 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "akili-example",
"version": "0.6.1",
"version": "0.6.5",
"description": "Akili example site",
"main": "app.js",
"author": {
Expand All @@ -24,7 +24,7 @@
"url": "https://github.com/ortexx/akili-example"
},
"dependencies": {
"@fortawesome/fontawesome-free-webfonts": "^1.0.4",
"@fortawesome/fontawesome-free-webfonts": "^1.0.5",
"akili": "~0.6.0",
"akili-connect": "~0.6.0",
"bootstrap": "^4.0.0",
Expand All @@ -41,7 +41,7 @@
"babel-preset-stage-3": "^6.24.1",
"clean-webpack-plugin": "^0.1.19",
"css-loader": "^0.28.11",
"eslint": "^4.19.0",
"eslint": "^4.19.1",
"eslint-loader": "^2.0.0",
"extract-text-webpack-plugin": "^3.0.2",
"file-loader": "^1.1.11",
Expand Down
2 changes: 1 addition & 1 deletion src/components/post-cards/post-cards.html
Expand Up @@ -14,7 +14,7 @@
<i class="fa fa-pencil-alt"></i>
</a>
<a
on-click="${ event.stopPropagation(); this.removePost(this.loopValue) }"
on-click="${ event.stopPropagation(); this.deletePost(this.loopValue) }"
hidden="${ this.data.length < 2 }"
class="ml-2"
>
Expand Down
12 changes: 7 additions & 5 deletions src/components/post-cards/post-cards.js
Expand Up @@ -15,14 +15,15 @@ import Akili from 'akili';
export default class PostCards extends Akili.Component {
static matches = '[data]';
static template = require('./post-cards.html');
static events = ['select', 'delete'];

static define() {
Akili.component('post-cards', this);
}

created() {
this.scope.selectPost = this.selectPost.bind(this);
this.scope.removePost = this.removePost.bind(this);
this.scope.deletePost = this.deletePost.bind(this);
}

compiled() {
Expand All @@ -34,12 +35,13 @@ export default class PostCards extends Akili.Component {
this.attr('data', 'data');
}

selectPost(post) {
this.scope.data.forEach((item) => item.selected && delete item.selected);
post.selected = true;
selectPost(post) {
this.scope.data.forEach(item => item === post? (item.selected = true): delete item.selected);
this.attrs.onSelect.trigger(post.id);
}

removePost(post) {
deletePost(post) {
this.scope.data.forEach((item, i, arr) => item === post && arr.splice(i, 1));
this.attrs.onDelete.trigger(post.id);
}
}
5 changes: 3 additions & 2 deletions src/controllers/posts/posts.html
Expand Up @@ -2,10 +2,11 @@
<div class="input-group mb-5">
<input class="form-control" placeholder="search..." on-debounce="${ this.filter = event.target.value }">
</div>
<div >
<div>
<post-cards
data="${ this.filteredPosts = utils.filter(this.posts, this.filter, ['title', 'body']) }"
on-data="${ this.setPosts(event.detail) }"
on-select="${ this.selectPost(event.detail) }"
on-delete="${ this.deletePost(event.detail) }"
></post-cards>
</div>
<if is="${ !this.filteredPosts.length }">
Expand Down
22 changes: 15 additions & 7 deletions src/controllers/posts/posts.js
@@ -1,7 +1,5 @@

import Akili from 'akili';
import router from 'akili/src/services/router';
import store from 'akili/src/services/store';
import { getAll as getPosts } from '../../actions/posts';

/**
Expand All @@ -28,11 +26,21 @@ export default class Posts extends Akili.Component {
}

created() {
this.scope.setPosts = this.setPosts.bind(this);
this.scope.posts = store.posts;
this.scope.selectPost = this.selectPost.bind(this);
this.scope.deletePost = this.deletePost.bind(this);
}

compiled() {
this.store('posts', 'posts');
}

setPosts(posts = []) {
store.posts = this.scope.posts = posts;
selectPost(id) {
this.scope.posts.forEach(post => post.id == id? (post.selected = true): delete post.selected);
}
}

deletePost(id) {
this.scope.posts.forEach((post, i, arr) => post.id == id && arr.splice(i, 1));
}
}


3 changes: 1 addition & 2 deletions src/controllers/users/users.html
Expand Up @@ -4,8 +4,7 @@
</div>
<div>
<user-cards
data="${ this.filteredUsers = utils.filter(this.users, this.filter, 'name') }"
on-data="${ this.setPosts(event.detail) }"
data="${ this.filteredUsers = utils.filter(this.users, this.filter, 'name') }"
></user-cards>
</div>
<if is="${ !this.filteredUsers.length }">
Expand Down

0 comments on commit 70b554d

Please sign in to comment.