Skip to content
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

Took optilude's concept and ran with it. Added more reactivity. #1

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
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ Running:
* Run `bower install` (Bower)
* Run `mrt install` (Meteorite)

Adding more posts:

```javascript
postCollection.insert({
username: 'Test user',
text: 'all',
favorite: false,
avatar:'http://linustechtips.com/main/uploads/profile/photo-122199.gif'
});
```

Some key points:

* Polymer is installed using Bower and served from the `public/` directory.
Expand Down
19 changes: 14 additions & 5 deletions client/pages/social.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,23 @@
<core-header-panel>
<core-toolbar>
<paper-tabs id="tabs" selected="all" self-end>
<paper-tab name="all">ALL</paper-tab>
<paper-tab name="favorites">FAVORITES</paper-tab>
{{#each getTabs}}
<paper-tab name="{{name}}">{{text}}</paper-tab>
{{/each}}
</paper-tabs>
</core-toolbar>
<div class="container" layout vertical center>
{{#if showPosts}}
<post-list show="all"></post-list>
{{/if}}
<post-list show="all">
{{#each getPosts}}
<post-card
favorite="{{favorite}}"
on-favorite-tap="">
<img src="{{avatar}}" width="70" height="70">
<h2>{{username}}</h2>
<p>{{text}}</p>
</post-card>
{{/each}}
</post-list>
</div>
</core-header-panel>
</template>
109 changes: 103 additions & 6 deletions client/pages/social.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,112 @@
tabCollection = new Meteor.Collection(null);
postCollection = new Meteor.Collection(null);


Template.social.showPosts = function() {
// dumb example to test reactivity; do `Session.set('showPosts', false)` in
// the console to hide posts
var showPosts = Session.get('showPosts');
return showPosts !== undefined? showPosts : true;
};

Template.social.rendered = function() {
var list = document.querySelector('post-list');
var tabs = document.querySelector('paper-tabs');
Template.social.getTabs = function () {
return tabCollection.find();
};

Template.social.getPosts = function (filter) {
var selector = {};

tabs.addEventListener('core-select', function() {
list.show = tabs.selected;
});
if(Session.get('selectedTab') === 'favorites') {
selector.favorite = true;
}

return postCollection.find(selector);
};

Template.social.events = {
'click #tabs': function (e, template) {
var data = UI.getElementData(event.target);
Session.set('selectedTab', data.name);
},
'favorite-tap': function (e, template) {
var data = UI.getElementData(event.target);
postCollection.update(data._id, {$set: {favorite:!data.favorite}});
}
}

Meteor.startup(function () {
if (!tabCollection.find().count()) {
tabCollection.insert({
name: 'all',
text: 'all'
});
tabCollection.insert({
name: 'favorites',
text: 'favorites'
})
}
if (!postCollection.find().count()) {
var posts = [
{
"uid": 1,
"text" : "Have you heard about the Web Components revolution?",
"username" : "Eric",
"avatar" : "../images/avatar-01.svg",
"favorite": false
},
{
"uid": 2,
"text" : "Loving this Polymer thing.",
"username" : "Rob",
"avatar" : "../images/avatar-02.svg",
"favorite": false
},
{
"uid": 3,
"text" : "So last year...",
"username" : "Dimitri",
"avatar" : "../images/avatar-03.svg",
"favorite": false
},
{
"uid": 4,
"text" : "Pretty sure I came up with that first.",
"username" : "Ada",
"avatar" : "../images/avatar-07.svg",
"favorite": false
},
{
"uid": 5,
"text" : "Yo, I heard you like components, so I put a component in your component.",
"username" : "Grace",
"avatar" : "../images/avatar-08.svg",
"favorite": false
},
{
"uid": 6,
"text" : "Centralize, centrailize.",
"username" : "John",
"avatar" : "../images/avatar-04.svg",
"favorite": false
},
{
"uid": 7,
"text" : "Has anyone seen my cat?",
"username" : "Zelda",
"avatar" : "../images/avatar-06.svg",
"favorite": false
},
{
"uid": 8,
"text" : "Decentralize!",
"username" : "Norbert",
"avatar" : "../images/avatar-05.svg",
"favorite": false
}
];

_.each(posts, function (post) {
postCollection.insert(post);
});
}
});
58 changes: 0 additions & 58 deletions public/api/posts.json

This file was deleted.

25 changes: 15 additions & 10 deletions public/post-card.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,21 @@
fill: #da4336;
}
</style>
<div class="card-header" layout horizontal center>
<content select="img"></content>
<content select="h2"></content>
</div>
<core-icon-button
id="favicon"
icon="favorite"
on-tap="{{favoriteTapped}}"></core-icon-button>
<content></content>

<div class="cardContainer" data-uid="{{uid}}" >
<div class="card-header" layout horizontal center>
<content select="img"></content>
<content select="h2"></content>
</div>

<core-icon-button
id="favicon"
icon="favorite"
on-tap="{{favoriteTapped}}"></core-icon-button>

<div class="card-content"><content></content></div>
</div>

</template>
<script>
Polymer('post-card', {
Expand All @@ -57,7 +63,6 @@
}
},
favoriteTapped: function(event, detail, sender) {
this.favorite = !this.favorite;
this.fire('favorite-tap');
}
});
Expand Down
20 changes: 5 additions & 15 deletions public/post-list.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

<link rel="import" href="/bower_components/polymer/polymer.html">
<link rel="import" href="/post-service/post-service.html">
<link rel="import" href="/bower_components/core-selector/core-selector.html">
<link rel="import" href="post-card.html">

<polymer-element name="post-list" attributes="show">
<polymer-element name="post-list" attributes="show" role="postlist" extends="core-selector">
<template>
<style>
:host {
Expand All @@ -14,19 +15,8 @@
}
</style>

<post-service id="service" posts="{{posts}}"></post-service>

<div layout vertical center>
<template repeat="{{post in posts}}">
<post-card
favorite="{{post.favorite}}"
on-favorite-tap="{{handleFavorite}}"
hidden?="{{show == 'favorites' && !post.favorite}}">
<img src="{{post.avatar}}" width="70" height="70">
<h2>{{post.username}}</h2>
<p>{{post.text}}</p>
</post-card>
</template>
<div id="postsContainer" layout vertical center>
<shadow></shadow>
</div>
</template>

Expand Down
89 changes: 0 additions & 89 deletions public/post-service/post-service.html

This file was deleted.