Skip to content

Commit

Permalink
fixed res.render issue so url always stays at /
Browse files Browse the repository at this point in the history
  • Loading branch information
nsafai committed Nov 6, 2018
1 parent 5609eee commit df647b9
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 33 deletions.
12 changes: 8 additions & 4 deletions public/stylesheets/style.css

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

2 changes: 1 addition & 1 deletion public/stylesheets/style.css.map

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

20 changes: 15 additions & 5 deletions public/stylesheets/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ body {
margin-bottom: 0.8rem;
}

.subheader-description {
max-width:800px;
}

.profile-settings {
// border: 2px solid $light-grey;
}

.switch {
position: relative;
display: inline-block;
Expand Down Expand Up @@ -120,8 +128,9 @@ body {
width: 40%;

#code-name {
width:100%;
width: 100%;
}

.copy-btn {
border-radius: 0.2em;
background-color: $black;
Expand Down Expand Up @@ -207,6 +216,7 @@ body {
color: white;
padding: 0.4em 0.25em;
width: 100%;
border:none;
}

.prop-voted {
Expand All @@ -219,27 +229,27 @@ body {
border: 2px solid $light-grey;

.card-header {
text-align: right;
text-align: center;
padding-right: 1em;
}

.card-body {
// no padding on the right side
padding: 0.25em 0.0em 0.25em 0.25em;
padding: 0.5em;
}
}

.card.card__cons {
border: 2px solid $light-grey;

.card-header {
text-align: left;
text-align: center;
padding-left: 1em;
}

.card-body {
// no padding on the left side
padding: 0.25em 0.25em 0.25em 0;
padding: 0.5em;
}
}
}
Expand Down
18 changes: 14 additions & 4 deletions routes/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var express = require('express');
var router = express.Router();
const auth = require('./helpers/auth');

const User = require('../models/user');
const Proposition = require('../models/proposition');

// set layout variables
Expand All @@ -15,13 +15,23 @@ router.use(function(req, res, next) {

/* GET home page. */
router.get('/', function(req, res, next) {
// console.log(req);
Proposition.find({}, function(err, props) {
if (err) {
console.error(err);
} else {
res.render('index', {
props: props
});
if (res.locals.user) {
User.findById(res.locals.user._id, function (err, user) {
res.render('index', {
props: props,
user: user
});
});
} else {
res.render('index', {
props: props
});
}
}
})
});
Expand Down
11 changes: 6 additions & 5 deletions routes/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,12 @@ router.post('/save-vote', auth.requireLogin, function(req, res, next) {
if (err) {
console.error(err);
} else {
User.findById(res.locals.user._id, function (err, updatedUser) {
res.render('index', {
props: props,
user: updatedUser
});
User.findById(res.locals.user._id, function (err, user) {
// res.render('index', {
// props: props,
// user: user
// });
res.redirect('/');
});
}
})
Expand Down
31 changes: 17 additions & 14 deletions views/index.hbs
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
<div class="top">
<h1 id="title">{{title}}</h1>
<p>People are busy. People often don't vote for propositions
because they don't know what they're about. We've synthesized
the important information below.</p>
<h2>For SF Residents</h2>
<p class="subheader-description">People are busy. People often skip voting for propositions
because they don't know enough about them. We've synthesized the important information below.
If you log in, you can save your votes and share them with others.</p>
{{#if user}}
<div class="toggle-profile">
Private
<label class="switch">
<input id="privacyToggle" type="checkbox" {{#if user.profilePublic}} checked {{/if}}>
<span class="slider round"></span>
</label>
Public
</div>
<div class="copy-section" id="copy-section" {{#if user.profilePublic}} {{else}} style="display:none" {{/if}}>
<input type="text" class="code-name" id="code-name" readonly="readonly" value="http://votersguide.co/{{user.codeName}}">
<button class="copy-btn anim-hov-fast" onClick="copyText('code-name')">Copy</button>
<div class="profile-settings">
<div class="toggle-profile">
Private
<label class="switch">
<input id="privacyToggle" type="checkbox" {{#if user.profilePublic}} checked {{/if}}>
<span class="slider round"></span>
</label>
Public
</div>
<div class="copy-section" id="copy-section" {{#if user.profilePublic}} {{else}} style="display:none" {{/if}}>
<input type="text" class="code-name" id="code-name" readonly="readonly" value="http://votersguide.co/{{user.codeName}}">
<button class="copy-btn anim-hov-fast" onClick="copyText('code-name')">Copy</button>
</div>
</div>
{{/if}}
</div>
Expand Down

0 comments on commit df647b9

Please sign in to comment.