Skip to content
This repository has been archived by the owner on Apr 24, 2020. It is now read-only.

Commit

Permalink
Initial
Browse files Browse the repository at this point in the history
  • Loading branch information
mrwisu committed Jul 23, 2018
0 parents commit 98cf5c2
Show file tree
Hide file tree
Showing 28 changed files with 1,904 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
18 changes: 18 additions & 0 deletions .meteor/.finished-upgraders
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# This file contains information which helps Meteor properly upgrade your
# app when you run 'meteor update'. You should check it into version control
# with your project.

notices-for-0.9.0
notices-for-0.9.1
0.9.4-platform-file
notices-for-facebook-graph-api-2
1.2.0-standard-minifiers-package
1.2.0-meteor-platform-split
1.2.0-cordova-changes
1.2.0-breaking-changes
1.3.0-split-minifiers-package
1.4.0-remove-old-dev-bundle-link
1.4.1-add-shell-server-package
1.4.3-split-account-service-packages
1.5-add-dynamic-import-package
1.7-split-underscore-from-meteor-base
1 change: 1 addition & 0 deletions .meteor/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
local
7 changes: 7 additions & 0 deletions .meteor/.id
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file contains a token that is unique to your project.
# Check it into your repository along with the rest of this directory.
# It can be used for purposes such as:
# - ensuring you don't accidentally deploy one app on top of another
# - providing package authors with aggregated statistics

y86kuay3dddt.flkjpma3sowg
22 changes: 22 additions & 0 deletions .meteor/packages
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Meteor packages used by this project, one per line.
# Check this file (and the other files in this directory) into your repository.
#
# 'meteor add' and 'meteor remove' will edit this file for you,
# but you can also edit it by hand.

[email protected] # Packages every Meteor app needs to have
[email protected] # Packages for a great mobile UX
[email protected] # The database Meteor supports right now
[email protected] # Compile .html files into Meteor Blaze views
[email protected] # Reactive variable for tracker
[email protected] # Meteor's client-side reactive programming library

[email protected] # CSS minifier run for production mode
[email protected] # JS minifier run for production mode
[email protected] # ECMAScript 5 compatibility for older browsers
[email protected] # Enable ECMAScript2015+ syntax in app code
[email protected] # Server-side component of the `meteor shell` command

[email protected]
underscore
session
2 changes: 2 additions & 0 deletions .meteor/platforms
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
server
browser
1 change: 1 addition & 0 deletions .meteor/release
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[email protected]
87 changes: 87 additions & 0 deletions .meteor/versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
1 change: 1 addition & 0 deletions client/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* CSS declarations go here */
7 changes: 7 additions & 0 deletions client/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<head>
<title>Short Link</title>
</head>

<body>
<div id="app"></div>
</body>
9 changes: 9 additions & 0 deletions client/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Meteor } from 'meteor/meteor';
import ReactDOM from 'react-dom';

import { routes } from '../imports/routes/routes';
import '../imports/startup/simple-schema-configuration';

Meteor.startup(() => {
ReactDOM.render(routes, document.getElementById('app'));
});
81 changes: 81 additions & 0 deletions imports/api/links.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import SimpleSchema from 'simpl-schema';
import shortid from 'shortid';

export const Links = new Mongo.Collection('links');

if (Meteor.isServer)
{
Meteor.publish('links', function () {
return Links.find({ userId: this.userId });
});
}

Meteor.methods({
'links.insert'(url) {
if (!this.userId)
{
throw new Meteor.Error('not-authorised')
}

new SimpleSchema({
url: {
type: String,
label: 'Your link',
regEx: SimpleSchema.RegEx.Url
}
}).validate( { url } );

Links.insert({
_id: shortid.generate(),
url,
userId: this.userId,
visible: true,
visitedCount: 0,
lastVisitedAt: null
});
},
'links.setVisibility'(_id, visible) {
if (!this.userId)
{
throw new Meteor.Error('not-authorised');
}

new SimpleSchema({
_id: {
type: String,
min: 1
},
visible: {
type: Boolean,
}
}).validate({ _id, visible });

Links.update(
{
_id,
userId: this.userId
},
{
$set: {visible}
}
);
},
'links.trackVisit'(_id) {
new SimpleSchema({
_id: {
type: String,
min: 1
}
}).validate({ _id });

Links.update({ _id },
{
$inc: {visitedCount: 1},
$set: {lastVisitedAt: new Date().getTime()}
}
);

}
});
16 changes: 16 additions & 0 deletions imports/api/users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Meteor } from 'meteor/meteor';
import SimpleSchema from 'simpl-schema';
import { Accounts } from 'meteor/accounts-base';

Accounts.validateNewUser((user) => {
const email = user.emails[0].address;

new SimpleSchema({
email: {
type: String,
regEx: SimpleSchema.RegEx.Email
}
}).validate( { email } );

return true;
});
23 changes: 23 additions & 0 deletions imports/routes/routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Meteor } from 'meteor/meteor';
import React from 'react';
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';

import Authentication from '../ui/Authentication';
import Link from '../ui/Link';
import Login from '../ui/Login';
import NotFound from '../ui/NotFound';
import Signup from '../ui/Signup';

export const routes = (
<Router>
<div>
<Route path='*' component={Authentication}/>
<Switch>
<Route exact path='/' component={Login}/>
<Route path='/signup' component={Signup}/>
<Route path='/links' component={Link}/>
<Route path='*' component={NotFound}/>
</Switch>
</div>
</Router>
);
6 changes: 6 additions & 0 deletions imports/startup/simple-schema-configuration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Meteor } from 'meteor/meteor';
import SimpleSchema from 'simpl-schema';

SimpleSchema.defineValidationErrorTransform(e => {
return new Meteor.Error(400, e.message);
});
40 changes: 40 additions & 0 deletions imports/ui/AddLink.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from 'react';
import { Meteor } from 'meteor/meteor';

export default class AddLink extends React.Component {
constructor(props) {
super(props);
this.state = {
url: ''
}
}
onSubmit(e) {
e.preventDefault();
const url = this.refs.url.value.trim();
if (url)
{
Meteor.call('links.insert', url);
this.refs.url.value = '';
}
}
onChange(e) {
this.setState({url: e.target.value });
}
render() {
return (
<div>
<p>Add link</p>
<form onSubmit={this.onSubmit.bind(this)}>
<input
type="text"
ref="url"
placeholder="URL"
value={this.state.url}
onChange={this.onChange.bind(this)}
/>
<button>Add link</button>
</form>
</div>
);
}
}
24 changes: 24 additions & 0 deletions imports/ui/Authentication.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Tracker } from 'meteor/tracker';

const unauthenticatedPages = ['/', '/signup'];
const authenticatedPages = ['/links'];

export default ({ location, history }) => {
Tracker.autorun(() => {
const isAuthenticated = !!Meteor.userId();
// console.log('isAuthenticated', isAuthenticated);

const isUnauthenticatedPage = unauthenticatedPages.includes(location.pathname);
const isAuthenticatedPage = authenticatedPages.includes(location.pathname);

if (isUnauthenticatedPage && isAuthenticated)
{
history.replace('/links');
}
if (isAuthenticatedPage && !isAuthenticated)
{
history.replace('/');
}
});
return null;
};
17 changes: 17 additions & 0 deletions imports/ui/Link.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';

import LinksList from './LinksList'
import PrivateHeader from './PrivateHeader';
import AddLink from './AddLink';
import LinksListFilters from './LinksListFilters';

export default () => {
return (
<div>
<PrivateHeader title='Links Page'/>
<LinksListFilters/>
<LinksList/>
<AddLink/>
</div>
);
};
Loading

0 comments on commit 98cf5c2

Please sign in to comment.