Skip to content

Commit

Permalink
Separate Wrapped (#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
avgupta456 authored Nov 26, 2023
1 parent 8fbfe4f commit 130a2de
Show file tree
Hide file tree
Showing 18 changed files with 190 additions and 99 deletions.
14 changes: 0 additions & 14 deletions backend/deploy/Dockerfile

This file was deleted.

1 change: 0 additions & 1 deletion backend/src/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# GLOBAL
LOCAL = os.getenv("LOCAL", "False") == "True"
PROD = os.getenv("PROD", "False") == "True"
DOCKER = os.getenv("DOCKER", "False") == "True"
PROJECT_ID = "github-334619"
BACKEND_URL = "https://api.githubtrends.io" if PROD else "http://localhost:8000"

Expand Down
3 changes: 3 additions & 0 deletions backend/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@

origins = [
"http://localhost:3000",
"http://localhost:3001",
"https://githubtrends.io",
"https://www.githubtrends.io",
"https://githubwrapped.io",
"https://www.githubwrapped.io",
]

app.add_middleware(
Expand Down
30 changes: 0 additions & 30 deletions docker-compose.yaml

This file was deleted.

8 changes: 0 additions & 8 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@ If you are interested in contributing to GitHub Trends, take a look through the

First, copy `backend/.env-template` into `backend/.env` and fill in the missing variables. Similarly, copy `frontend/.env-template` into `frontend/.env` and fill in the missing variables. Create a Google Cloud Platform service account and include the key in `backend/gcloud_key.json`. Then run:

### Docker (recommended)

```
docker-compose up --build -d
```

### Manual

With Python3.11, install the dependencies from `backend/requirements.txt` and run `yarn start`.

With Node16 and Yarn, install the dependencies from `frontend/package.json` and run on a separate terminal window `yarn start`.
Expand Down
3 changes: 0 additions & 3 deletions frontend/.dockerignore

This file was deleted.

3 changes: 2 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
"tailwindcss": "^3.3.5"
},
"scripts": {
"start": "react-scripts start",
"trends": "REACT_APP_MODE=trends react-scripts start",
"wrapped": "REACT_APP_MODE=wrapped PORT=3001 react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/api/wrapped.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import axios from 'axios';

import { SUBSCRIBER_URL } from '../constants';
import { BACKEND_URL } from '../constants';

const URL_PREFIX = `${SUBSCRIBER_URL}/wrapped`;
const URL_PREFIX = `${BACKEND_URL}/wrapped`;

const getValidUser = async (userId) => {
try {
Expand Down
21 changes: 15 additions & 6 deletions frontend/src/constants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-nested-ternary */
export const PROD = process.env.REACT_APP_PROD === 'true';

export const USE_LOGGER = true;
Expand All @@ -6,17 +7,25 @@ export const CLIENT_ID = PROD
? process.env.REACT_APP_PROD_CLIENT_ID
: process.env.REACT_APP_DEV_CLIENT_ID;

export const MODE = process.env.REACT_APP_MODE;

export const REDIRECT_URI = PROD
? 'https://www.githubtrends.io/user'
: 'http://localhost:3000/user';
? MODE === 'trends'
? 'https://www.githubtrends.io/user'
: 'https://www.githubtrends.io/user/wrapped'
: MODE === 'trends'
? 'http://localhost:3000/user'
: 'http://localhost:3000/user/wrapped';

console.log(REDIRECT_URI);

export const GITHUB_PRIVATE_AUTH_URL = `https://github.com/login/oauth/authorize?scope=user,repo&client_id=${CLIENT_ID}&redirect_uri=${REDIRECT_URI}/private`;
export const GITHUB_PUBLIC_AUTH_URL = `https://github.com/login/oauth/authorize?client_id=${CLIENT_ID}&redirect_uri=${REDIRECT_URI}/public`;

export const WRAPPED_URL = PROD
? 'https://www.githubwrapped.io'
: 'http://localhost:3001';

export const BACKEND_URL = PROD
? 'https://api.githubtrends.io'
: 'http://localhost:8000';

export const SUBSCRIBER_URL = PROD
? 'https://github-334619.uc.r.appspot.com'
: 'http://localhost:8000';
27 changes: 21 additions & 6 deletions frontend/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,30 @@ import ReactDOM from 'react-dom/client';
import { Provider } from 'react-redux';

import configureStore from './redux/store';
import App from './pages/App';
import { AppTrends, AppWrapped } from './pages/App';
import './index.css';

import { MODE } from './constants';

export const store = configureStore();

const root = ReactDOM.createRoot(document.getElementById('root'));

root.render(
<Provider store={store}>
<App />
</Provider>,
);
if (MODE === 'trends') {
root.render(
<Provider store={store}>
<AppTrends />
</Provider>,
);
} else if (MODE === 'wrapped') {
root.render(
<Provider store={store}>
<AppWrapped />
</Provider>,
);
} else {
// Throw an error if the mode is not set correctly.
throw new Error(
'REACT_APP_MODE must be set to "trends" or "wrapped" in your .env file.',
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,35 @@
import React, { useEffect } from 'react';
import { useSelector, useDispatch } from 'react-redux';

import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
import {
BrowserRouter as Router,
Routes,
Route,
useParams,
} from 'react-router-dom';

import Header from './Header';
import LandingScreen from '../Landing';
import DemoScreen from '../Demo';
import { SignUpScreen } from '../Auth';
import HomeScreen from '../Home';
import { SelectUserScreen, WrappedScreen } from '../Wrapped';
import SettingsScreen from '../Settings';
import { NoMatchScreen, RedirectScreen } from '../Misc';

import { setPrivateAccess as _setPrivateAccess } from '../../redux/actions/userActions';
import { getUserMetadata } from '../../api';
import { WRAPPED_URL } from '../../constants';
import Footer from './Footer';

function WrappedAuthRedirectScreen() {
const { rest } = useParams();
useEffect(() => {
const code = new URLSearchParams(window.location.search).get('code');
window.location.href = `${WRAPPED_URL}/${rest}?code=${code}`;
}, [rest]);

return null;
}

function App() {
const userId = useSelector((state) => state.user.userId);
Expand Down Expand Up @@ -47,28 +63,19 @@ function App() {
)}
<Route path="/demo" element={<DemoScreen />} />
<Route path="/user/redirect" element={<RedirectScreen />} />
<Route path="/user" element={<HomeScreen />} />
<Route
path="/user/wrapped/:rest"
element={<WrappedAuthRedirectScreen />}
/>
<Route path="/user/*" element={<HomeScreen />} />
<Route path="/wrapped/:userId/:year" element={<WrappedScreen />} />
<Route path="/wrapped/:userId" element={<WrappedScreen />} />
<Route path="/wrapped" element={<SelectUserScreen />} />
{isAuthenticated && (
<Route path="/settings" element={<SettingsScreen />} />
)}
<Route path="/:userId" element={<WrappedScreen />} />
<Route exact path="/" element={<LandingScreen />} />
<Route path="*" element={<NoMatchScreen />} />
</Routes>
</section>
<footer className="body-font">
<div className="bg-gray-100 border-t border-gray-300">
<div className="container mx-auto py-4 px-5">
<p className="text-gray-500 text-sm text-center">
© 2023 GitHub Trends
</p>
</div>
</div>
</footer>
<Footer />
</Router>
</div>
);
Expand Down
59 changes: 59 additions & 0 deletions frontend/src/pages/App/AppWrapped.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/* eslint-disable jsx-a11y/anchor-is-valid */

import React, { useEffect } from 'react';
import { useSelector, useDispatch } from 'react-redux';

import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';

import Header from './Header';
import { SignUpScreen } from '../Auth';
import { SelectUserScreen, WrappedScreen } from '../Wrapped';
import { NoMatchScreen } from '../Misc';

import { setPrivateAccess as _setPrivateAccess } from '../../redux/actions/userActions';
import { getUserMetadata } from '../../api';
import Footer from './Footer';

function App() {
const userId = useSelector((state) => state.user.userId);
const isAuthenticated = userId && userId.length > 0;

const dispatch = useDispatch();
const setPrivateAccess = (access) => dispatch(_setPrivateAccess(access));

useEffect(() => {
async function getPrivateAccess() {
if (userId && userId.length > 0) {
const result = await getUserMetadata(userId);
if (result !== null && result.private_access !== undefined) {
setPrivateAccess(result.private_access);
}
}
}
getPrivateAccess();
}, [userId]);

return (
<div className="h-screen flex flex-col">
<Router>
<Header />
<section className="bg-white text-gray-700 flex-grow">
<Routes>
{!isAuthenticated && (
<Route path="/signup" element={<SignUpScreen />} />
)}
<Route path="/" element={<SelectUserScreen />} />
<Route path="/public/" element={<SelectUserScreen />} />
<Route path="/private/" element={<SelectUserScreen />} />
<Route path="/:userId/:year" element={<WrappedScreen />} />
<Route path="/:userId" element={<WrappedScreen />} />
<Route path="*" element={<NoMatchScreen />} />
</Routes>
</section>
<Footer />
</Router>
</div>
);
}

export default App;
17 changes: 17 additions & 0 deletions frontend/src/pages/App/Footer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';

function Footer() {
return (
<footer className="body-font">
<div className="bg-gray-100 border-t border-gray-300">
<div className="container mx-auto py-4 px-5">
<p className="text-gray-500 text-sm text-center">
© 2023 GitHub Trends
</p>
</div>
</div>
</footer>
);
}

export default Footer;
5 changes: 3 additions & 2 deletions frontend/src/pages/App/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import App from './App';
import AppTrends from './AppTrends';
import AppWrapped from './AppWrapped';

export default App;
export { AppTrends, AppWrapped };
7 changes: 2 additions & 5 deletions frontend/src/pages/Landing/Landing.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,12 @@ function LandingScreen() {
</p>
<br />
<div>
<Link to="/wrapped/avgupta456" className="w-auto">
<Link to="/avgupta456" className="w-auto">
<Button className="my-4 mr-4 w-auto justify-center text-white text-xl 3xl:text-2xl bg-gray-700 hover:bg-gray-800">
Example
</Button>
</Link>
<Link
to={isAuthenticated ? `/wrapped/${userId}` : '/wrapped'}
className="w-auto"
>
<Link to={isAuthenticated ? `/${userId}` : '/'} className="w-auto">
<Button className="my-4 mr-4 w-auto justify-center text-white text-xl 3xl:text-2xl bg-blue-500 hover:bg-blue-600">
Get your Wrapped
</Button>
Expand Down
9 changes: 8 additions & 1 deletion frontend/src/pages/Settings/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,14 @@ const SettingsScreen = () => {
)}
</div>
)}
{selected === 'personalization' && <div>Personalization</div>}
{selected === 'personalization' && (
<div>
<p className="mb-1 text-2xl text-gray-700">Personalization</p>
<hr />
<br />
<p>Coming soon!</p>
</div>
)}
{selected === 'deleteAccount' && (
<div>
<p className="mb-1 text-2xl text-gray-700">Delete Account</p>
Expand Down
Loading

0 comments on commit 130a2de

Please sign in to comment.