elliot-wilson / WideWorld

A full-stack clone of Atlas Obscura using React / Redux, Ruby on Rails, PostgreSQL.
https://wide-world.herokuapp.com/#/
1 stars 0 forks source link
google-maps-api javascript react

Wide World

I love history and travel, so I spend a lot of time on Atlas Obscura. I decided to build my own version as a way of learning more about React, Redux, and Ruby on Rails, and I'm really happy with the results! Check out the live site!

Live Site

Technologies

The project was built with the following tools.

Features

Normalized Data in PostgreSQL and Redux

Interactive User Profile Maps

// user_profile.jsx

// this function chooses which list of locations to set as the "active" list
updateLocationSelection(selection) {

    const headers = ['locationVisits', 'locationWannaVisits', 'locationAdds', 'locationEdits'];
    const idx = headers.indexOf(selection);

    this.setState({locations: this.props[selection], selectedHeaderIdx: idx})
}

// the "active" locations get passed into the Map and the Index, and the function gets passed into User Details and the Map
render() {
    return (
        <div>
            <UserDetailsBox 
                user={user}
                locationVisits={locationVisits}
                locationWannaVisits={locationWannaVisits}
                locationAdds={locationAdds}
                locationEdits={locationEdits}
                updateLocationSelection={this.updateLocationSelection}
                />
            <section className="user-locations-box">
                <UserLocationsMapBox
                    user={user}
                    locations={this.state.locations}
                    selectedHeaderIdx={this.state.selectedHeaderIdx}
                    updateLocationSelection={this.updateLocationSelection}
                />
                <UserLocationsIndex
                    locations={this.state.locations}
                />
            </section>
        </div>
    )
}

Random Location

// random_location_container.js
class RandomLocation extends React.Component {

    constructor(props) {
        super(props);

        this.state = {
            fetchComplete: false
        }
    }

    componentDidMount() {
        this.props.fetchRandomLocation()
            .then(() => this.setState({fetchComplete: true}));
    }

    render() {
        const { location } = this.props;

        if (!this.state.fetchComplete) return (<div className="placeholder"></div>)

        return (
            <Redirect
                to={{
                    pathname: `/locations/${location.id}`,
                    state: {
                        randomLocation: location,
                        isRandom: true,
                    }
                }}
            />
        )
    }

}

// location.jsx

componentDidMount(){
    if (!this.props.isRandom) {
        this.props.fetchLocation(this.props.match.params.locationId);
    }
}

More features!

What's next?