Skip to content

Commit

Permalink
Newest Resources section!
Browse files Browse the repository at this point in the history
  • Loading branch information
towerofnix committed Jul 3, 2016
1 parent 0daf914 commit f295360
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 43 deletions.
52 changes: 12 additions & 40 deletions public/views/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -36,49 +36,21 @@

<main>
<h2>
Popular Resources
Newest Resources
</h2>

<div class='resources'>
<div class='resource'>
<a href='/users/liam48D/0'>
<img src='https://is.gd/NfqPMT'>

<h4> cute pug </h4>
</a>

<a href='/users/liam48D'> liam48D </a>
</div>

<div class='resource'>
<a href='/users/nanalan/0'>
<img src='https://cdn2.scratch.mit.edu/get_image/project/109764181_282x210.png'>

<h4> Selfie </h4>
</a>

<a href='/users/nanalan'> nanalan </a>
</div>

<div class='resource'>
<a href='/users/cheeseeater/0'>
<img src='https://cdn2.scratch.mit.edu/get_image/project/47606468_282x210.png'>

<h4> OpenSprites Logo </h4>
</a>

<a href='/users/cheeseeater'> cheeseeater </a>
</div>

<div class='resource'>
<a href='/users/kittylover/18'>
<img src='https://is.gd/tzxHhM'>

<h4> Kitty #18 </h4>
</a>

<a href='/users/kittylover'> kittylover </a>
</div>
{{#each recentResources}}
<div class='resource'>
<a href='/resources/{{this._id}}'>
<img src='/resources/{{this._id}}/raw'>
<h4>{{this.name}}</h4>
</a>
{{#each this.owners}}
<a href='/users/{{this}}'>{{this}}</a>
{{/each}}
</div>
{{/each}}
</div>
</main>

Expand Down
9 changes: 8 additions & 1 deletion server/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const Resource = mongoose.model('Resource', mongoose.Schema({
] },
data: Buffer,
owners: { type: Array, default: [] },
when: String,
when: Number,
}))

const Collection = mongoose.model('Collection', mongoose.Schema({
Expand Down Expand Up @@ -60,5 +60,12 @@ module.exports = {
done()
})
})
},

getRecentResources: async function(count) {
const resources = (await db.collections.resources.find())
.sort({when: -1})
.limit(4)
return resources
}
}
5 changes: 3 additions & 2 deletions server/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,10 @@ app.get('/resources/:id/raw', async function(req, res) {
}
})

app.get('/', function(req, res) {
app.get('/', async function(req, res) {
res.render('index', {
user: req.session.user
user: req.session.user,
recentResources: await (db.getRecentResources()).then(e => e.toArray())
})
})

Expand Down

2 comments on commit f295360

@towerofnix
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a good starting point to begin working on #9, #10, and #11.

@towerofnix
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Demo!

Demo

Please sign in to comment.