Skip to content

Instantly share code, notes, and snippets.

Avatar

Spencer Porter Porter97

View GitHub Profile
View app\static\js\components\Header(2).jsx
#...
const LoggedInView = props => {
if (props.currentUser) {
return (
#...
<li className='nav-item'>
<Link to="/collection-editor" className="nav-link">
New Collection
</Link>
</li>
View app\static\js\reducers\collection(1).jsx
export default (state = {}, action) => {
switch(action.type) {
case 'COLLECTION_PAGE_LOADED':
return {
...state,
collection: action.payload.collection
};
case 'COLLECTION_PAGE_UNLOADED':
return {};
default:
View app\static\js\AppRouter(11).jsx
#...
import Collection from './components/collection/Collection'
#...
class AppRouter extends Component {
#...
render() {
return (
View app\static\js\components\collection\CollectionActions(1).jsx
import { Link } from 'react-router-dom';
import React from 'react';
import agent from '../../agent';
import { connect } from 'react-redux';
const mapDispatchToProps = dispatch => ({
onClickDelete: payload =>
dispatch({ type: 'DELETE_COLLECTION', payload })
});
View gist:cf7e96cca5ce1565b215feb3ecfec24e
#...
export default (state = defaultState, action) => {
switch(action.type) {
#...
case 'COLLECTION_SUBMITTED':
const redirectUrl = `collection/${action.payload.collection.id}`;
return { ...state, redirectTo: redirectUrl };
case 'DELETE_COLLECTION':
return { ...state, redirectTo: '/' };
#...
View app\static\js\components\collection\CollectionMeta(1).jsx
import React from 'react';
import { Link } from 'react-router-dom';
import CollectionActions from './CollectionActions';
const CollectionMeta = props => {
const collection = props.collection;
return (
<div className="collection-meta">
<Link to={`/@${collection.author.username}`}>
<img src={collection.author.image} alt={collection.author.username} />
View app\static\js\components\collection\Collection(1).jsx
import React from 'react';
import agent from '../../agent'
import { connect } from 'react-redux';
import CollectionMeta from './CollectionMeta'
const mapStateToProps = state => ({
...state.collection,
currentUser: state.common.currentUser
View app\main\views(22).py
from flask import render_template, jsonify, flash, abort
from .forms import EditProfileForm, CollectionForm
from .errors import page_not_found, internal_server_error
from ..models import User, Collection, Permission'
#...
@main.route('/collections/<int:id>')
def get_collection(id):
collection = Collection.query.get_or_404(id)
return {'collection': collection.to_json()}
View app\models(23).py
#...
class Collection(db.Model):
#...
def to_json(self):
json_collection = {
'id': self.id,
'name': self.name,
'description': self.description,
'author': self.author.to_json(),
View app\main\forms(6).py
#...
from wtforms.validators import Length, Regexp, DataRequired
#...
class CollectionForm(FlaskForm):
class Meta:
csrf = False
name = StringField('name', validators=[DataRequired()])
description = StringField('description', validators=[DataRequired()])
You can’t perform that action at this time.