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

Finish All Release #10

Open
wants to merge 2 commits 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
39 changes: 39 additions & 0 deletions client/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Twatter</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.6.2/css/bulma.min.css">
<script defer src="https://use.fontawesome.com/releases/v5.0.6/js/all.js"></script>
</head>
<body>
<h1 id="header">Welcome to Twatt</h1>
<div class="field">
<label class="label">What's your Idea Today?</label>
<div class="control">
<input class="input" id="tweet" type="text" placeholder="Your Big Idea Today">
</div>
<button class="button is-primary" id="button-tweet">Tweet</button>
</div>
<div class="field">
<label class="label">What happen in the world?</label>
<div class="control">
<input class="input" id="search" type="text" placeholder="Today's headline is..">
</div>
<button class="button is-primary" id="button-search">Search</button>
</div>
<div class="newtimeline"></div>
<div class="timeline"><br></div>
<div class="search-list"><br></div>
</body>
<script
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous">
</script>
<script src="./script/timeline.js"></script>
<script src="./script/post.js"></script>
<script src="./script/search.js"></script>

</html>
49 changes: 49 additions & 0 deletions client/script/post.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
$("#button-tweet").click(()=> {
$.ajax({
url : "http://localhost:3000/api/twatt",
method : "post",
data : {
tweet : $("#tweet").val()
},
dataType : "json",
success : (data) => {
console.log(data);
$(".newtimeline").append(
`<div class="box">
<article class="media">
<div class="media-left">
<figure class="image is-64x64">
<img src=${data.tweet.user.profile_image_url} alt="Image">
</figure>
</div>
<div class="media-content">
<div class="content">
<p>
<strong>${data.tweet.user.name}</strong> <small>${data.tweet.user.screen_name}</small> <small>31m</small>
<br>
${data.tweet.text}
</p>
</div>
<nav class="level is-mobile">
<div class="level-left">
<a class="level-item">
<span class="icon is-small"><i class="fas fa-reply"></i></span>
</a>
<a class="level-item">
<span class="icon is-small"><i class="fas fa-retweet"></i></span>
</a>
<a class="level-item">
<span class="icon is-small"><i class="fas fa-heart"></i></span>
</a>
</div>
</nav>
</div>
</article>
</div>`
)
},
error : (err) => {
console.log(err);
}
})
})
51 changes: 51 additions & 0 deletions client/script/search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
$("#button-search").click(() => {
$.ajax({
url : "http://localhost:3000/api/twatt/search",
method : "get",
data : {
search: $("#search").val()
},
dataType : "json",
success : (data) => {
console.log(data);
data.tweet.statuses.map(value => {
$(".search-list").append(
`<div class="box">
<article class="media">
<div class="media-left">
<figure class="image is-64x64">
<img src=${value.user.profile_image_url} alt="Image">
</figure>
</div>
<div class="media-content">
<div class="content">
<p>
<strong>${value.user.name}</strong> <small>${value.user.screen_name}</small> <small>31m</small>
<br>
${value.text}
</p>
</div>
<nav class="level is-mobile">
<div class="level-left">
<a class="level-item">
<span class="icon is-small"><i class="fas fa-reply"></i></span>
</a>
<a class="level-item">
<span class="icon is-small"><i class="fas fa-retweet"></i></span>
</a>
<a class="level-item">
<span class="icon is-small"><i class="fas fa-heart"></i></span>
</a>
</div>
</nav>
</div>
</article>
</div>`
)
})
},
error : (err) => {
console.log(err);
}
})
})
45 changes: 45 additions & 0 deletions client/script/timeline.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
$.ajax({
url : "http://localhost:3000/api/twatt/user",
dataType : "json",
type : "get",
success : (data) => {
data.timeline.map(value => {
$(".timeline").append(
`<div class="box">
<article class="media">
<div class="media-left">
<figure class="image is-64x64">
<img src=${value.user.profile_image_url} alt="Image">
</figure>
</div>
<div class="media-content">
<div class="content">
<p>
<strong>${value.user.name}</strong> <small>${value.user.screen_name}</small> <small>31m</small>
<br>
${value.text}
</p>
</div>
<nav class="level is-mobile">
<div class="level-left">
<a class="level-item">
<span class="icon is-small"><i class="fas fa-reply"></i></span>
</a>
<a class="level-item">
<span class="icon is-small"><i class="fas fa-retweet"></i></span>
</a>
<a class="level-item">
<span class="icon is-small"><i class="fas fa-heart"></i></span>
</a>
</div>
</nav>
</div>
</article>
</div>`
)
})
},
error : (err) => {
console.log(err);
}
})
49 changes: 49 additions & 0 deletions server/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const express = require('express');
const path = require('path');
const favicon = require('serve-favicon');
const logger = require('morgan');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const OAuth = require('oauth');
require('dotenv').config()
const cors = require('cors')

const index = require('./routes/index');
const twatt = require('./routes/twatt.route')
const app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use(cors())

app.use('/', index);
app.use('/api/twatt', twatt)

// catch 404 and forward to error handler
app.use(function(req, res, next) {
const err = new Error('Not Found');
err.status = 404;
next(err);
});

// error handler
app.use(function(err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};

// render the error page
res.status(err.status || 500);
res.render('error');
});

module.exports = app;
90 changes: 90 additions & 0 deletions server/bin/www
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env node

/**
* Module dependencies.
*/

var app = require('../app');
var debug = require('debug')('twatt:server');
var http = require('http');

/**
* Get port from environment and store in Express.
*/

var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);

/**
* Create HTTP server.
*/

var server = http.createServer(app);

/**
* Listen on provided port, on all network interfaces.
*/

server.listen(port);
server.on('error', onError);
server.on('listening', onListening);

/**
* Normalize a port into a number, string, or false.
*/

function normalizePort(val) {
var port = parseInt(val, 10);

if (isNaN(port)) {
// named pipe
return val;
}

if (port >= 0) {
// port number
return port;
}

return false;
}

/**
* Event listener for HTTP server "error" event.
*/

function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}

var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;

// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
}

/**
* Event listener for HTTP server "listening" event.
*/

function onListening() {
var addr = server.address();
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
}
Loading