feat: traversal of dates in Seek component
This commit is contained in:
26
src/App.js
26
src/App.js
@@ -16,6 +16,7 @@ import { withAuthentication } from "./components/session";
|
|||||||
|
|
||||||
const RouteLayout = styled.div`
|
const RouteLayout = styled.div`
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
|
padding: 0 10px;
|
||||||
max-width: 720px;
|
max-width: 720px;
|
||||||
min-height: calc(100vh - 60px);
|
min-height: calc(100vh - 60px);
|
||||||
background-color: ${props => props.theme.colors.bodyBackground};
|
background-color: ${props => props.theme.colors.bodyBackground};
|
||||||
@@ -30,15 +31,12 @@ class App extends Component {
|
|||||||
onChangeTheme = () => {
|
onChangeTheme = () => {
|
||||||
const { selectedTheme } = this.state;
|
const { selectedTheme } = this.state;
|
||||||
const root = document.documentElement;
|
const root = document.documentElement;
|
||||||
console.log(root);
|
|
||||||
const newTheme = selectedTheme === "LIGHT" ? "DARK" : "LIGHT";
|
const newTheme = selectedTheme === "LIGHT" ? "DARK" : "LIGHT";
|
||||||
root.style.setProperty(
|
root.style.setProperty(
|
||||||
"background-color",
|
"background-color",
|
||||||
theme[newTheme].colors.bodyBackground
|
theme[newTheme].colors.bodyBackground
|
||||||
);
|
);
|
||||||
this.setState(prevState => ({
|
this.setState({ selectedTheme: newTheme });
|
||||||
selectedTheme: newTheme
|
|
||||||
}));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@@ -50,12 +48,20 @@ class App extends Component {
|
|||||||
<Router>
|
<Router>
|
||||||
<Navbar toggleTheme={this.onChangeTheme} />
|
<Navbar toggleTheme={this.onChangeTheme} />
|
||||||
<RouteLayout>
|
<RouteLayout>
|
||||||
<Route path="/:year(\d+)" component={Year} />
|
<Route path="/:year(\d+)" component={Year} exact />
|
||||||
<Route path="/:year(\d+)/:month(\d+)" component={Month} />
|
<Route
|
||||||
<Route path="/:year(\d+)/:month(\d+)/:day(\d+)" component={Day} />
|
path="/:year(\d+)/:month(0[1-9]|1[0-2]+)"
|
||||||
<Route path="/user" component={User} />
|
component={Month}
|
||||||
<Route path="/login" component={Login} />
|
exact
|
||||||
<Route path="/register" component={Register} />
|
/>
|
||||||
|
<Route
|
||||||
|
path="/:year(\d+)/:month(0[1-9]|1[0-2]+)/:day(\d+)"
|
||||||
|
component={Day}
|
||||||
|
exact
|
||||||
|
/>
|
||||||
|
<Route path="/user" component={User} exact />
|
||||||
|
<Route path="/login" component={Login} exact />
|
||||||
|
<Route path="/register" component={Register} exact />
|
||||||
</RouteLayout>
|
</RouteLayout>
|
||||||
</Router>
|
</Router>
|
||||||
</ThemeProvider>
|
</ThemeProvider>
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
ChevronRight,
|
ChevronRight,
|
||||||
Circle,
|
Circle,
|
||||||
Moon,
|
Moon,
|
||||||
|
Sun,
|
||||||
User
|
User
|
||||||
} from "react-feather";
|
} from "react-feather";
|
||||||
import { withTheme } from "emotion-theming";
|
import { withTheme } from "emotion-theming";
|
||||||
@@ -21,7 +22,7 @@ const IconBase = styled.div`
|
|||||||
transition: 0.1s all ease-in-out;
|
transition: 0.1s all ease-in-out;
|
||||||
color: ${props => props.theme.colors.secondary};
|
color: ${props => props.theme.colors.secondary};
|
||||||
&:hover {
|
&:hover {
|
||||||
background-color: ${props => props.theme.colors.hover};
|
background-color: ${props => !props.disabled && props.theme.colors.hover};
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
@@ -34,6 +35,7 @@ const Icon = ({ name, ...rest }) => (
|
|||||||
{name === "ChevronRight" && <ChevronRight />}
|
{name === "ChevronRight" && <ChevronRight />}
|
||||||
{name === "Circle" && <Circle />}
|
{name === "Circle" && <Circle />}
|
||||||
{name === "Moon" && <Moon />}
|
{name === "Moon" && <Moon />}
|
||||||
|
{name === "Sun" && <Sun />}
|
||||||
{name === "User" && <User />}
|
{name === "User" && <User />}
|
||||||
</IconBase>
|
</IconBase>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import { withTheme } from "emotion-theming";
|
|||||||
import { todayUrl, yearUrl } from "../../utils/date";
|
import { todayUrl, yearUrl } from "../../utils/date";
|
||||||
|
|
||||||
import Icon from "../Icon";
|
import Icon from "../Icon";
|
||||||
import SignOut from "../SignOut";
|
|
||||||
import { withAuthentication } from "../session";
|
import { withAuthentication } from "../session";
|
||||||
|
|
||||||
const Header = styled.div`
|
const Header = styled.div`
|
||||||
@@ -16,6 +15,7 @@ const Header = styled.div`
|
|||||||
display: grid;
|
display: grid;
|
||||||
grid-template-areas: "... nav ...";
|
grid-template-areas: "... nav ...";
|
||||||
grid-template-columns: 1fr minmax(240px, 720px) 1fr;
|
grid-template-columns: 1fr minmax(240px, 720px) 1fr;
|
||||||
|
grid-gap: 10px;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
border-width: 1px;
|
border-width: 1px;
|
||||||
border-color: ${props => props.theme.colors.quarternary};
|
border-color: ${props => props.theme.colors.quarternary};
|
||||||
@@ -43,7 +43,10 @@ const Navbar = ({ authUser, theme, toggleTheme }) => (
|
|||||||
<Nav>
|
<Nav>
|
||||||
<Logo>Logo</Logo>
|
<Logo>Logo</Logo>
|
||||||
<NavIcons>
|
<NavIcons>
|
||||||
<Icon onClick={() => toggleTheme()} name="Moon" />
|
<Icon
|
||||||
|
onClick={() => toggleTheme()}
|
||||||
|
name={theme.name === "Dark" ? "Sun" : "Moon"}
|
||||||
|
/>
|
||||||
{authUser ? (
|
{authUser ? (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<Link to={yearUrl()}>
|
<Link to={yearUrl()}>
|
||||||
@@ -55,8 +58,6 @@ const Navbar = ({ authUser, theme, toggleTheme }) => (
|
|||||||
<Link to={"/user"}>
|
<Link to={"/user"}>
|
||||||
<Icon name="User" />
|
<Icon name="User" />
|
||||||
</Link>
|
</Link>
|
||||||
|
|
||||||
<SignOut />
|
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
) : (
|
) : (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import styled from "@emotion/styled";
|
import styled from "@emotion/styled";
|
||||||
import { withTheme } from "emotion-theming";
|
import { withTheme } from "emotion-theming";
|
||||||
|
import { Link } from "react-router-dom";
|
||||||
|
|
||||||
import { SIZES } from "../../styles/constants";
|
import { SIZES } from "../../styles/constants";
|
||||||
import Icon from "../Icon";
|
import Icon from "../Icon";
|
||||||
@@ -25,12 +26,24 @@ const SeekArrows = styled.div`
|
|||||||
grid-gap: 10px;
|
grid-gap: 10px;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const Seek = ({ title = "", prev = "", next = "" }) => (
|
const Seek = ({ title = "", prev = "", next = "", disableNext, theme }) => (
|
||||||
<SeekHeader>
|
<SeekHeader>
|
||||||
<SeekH1>{title}</SeekH1>
|
<SeekH1>{title}</SeekH1>
|
||||||
<SeekArrows>
|
<SeekArrows>
|
||||||
<Icon name="ChevronLeft" />
|
<Link to={prev}>
|
||||||
<Icon name="ChevronRight" />
|
<Icon name="ChevronLeft" />
|
||||||
|
</Link>
|
||||||
|
<Link to={disableNext ? "#" : next}>
|
||||||
|
<Icon
|
||||||
|
disabled={disableNext}
|
||||||
|
name="ChevronRight"
|
||||||
|
style={{
|
||||||
|
color: disableNext
|
||||||
|
? theme.colors.quarternary
|
||||||
|
: theme.colors.secondary
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Link>
|
||||||
</SeekArrows>
|
</SeekArrows>
|
||||||
</SeekHeader>
|
</SeekHeader>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,5 +1,30 @@
|
|||||||
import React from "react";
|
import React, { Component } from "react";
|
||||||
|
import { addDays, subDays, format, isAfter, startOfYesterday } from "date-fns";
|
||||||
|
|
||||||
const Day = () => <div>Day</div>;
|
import Seek from "../../Seek";
|
||||||
|
|
||||||
|
class Day extends Component {
|
||||||
|
render() {
|
||||||
|
const {
|
||||||
|
match: {
|
||||||
|
params: { year, month, day }
|
||||||
|
}
|
||||||
|
} = this.props;
|
||||||
|
const currentDay = new Date(year, month - 1, day);
|
||||||
|
console.log(currentDay);
|
||||||
|
if (!currentDay) return;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Seek
|
||||||
|
title={format(currentDay, "YYYY MMM DD")}
|
||||||
|
prev={format(subDays(currentDay, 1), "/YYYY/MM/DD")}
|
||||||
|
next={format(addDays(currentDay, 1), "/YYYY/MM/DD")}
|
||||||
|
disableNext={isAfter(currentDay, startOfYesterday())}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default Day;
|
export default Day;
|
||||||
|
|||||||
@@ -1,5 +1,28 @@
|
|||||||
import React from "react";
|
import React, { Component } from "react";
|
||||||
|
import { addDays, subDays, format, isToday } from "date-fns";
|
||||||
|
|
||||||
const Month = () => <div>Month</div>;
|
import Seek from "../../Seek";
|
||||||
|
|
||||||
|
class Month extends Component {
|
||||||
|
render() {
|
||||||
|
const {
|
||||||
|
match: {
|
||||||
|
params: { year, month }
|
||||||
|
}
|
||||||
|
} = this.props;
|
||||||
|
const currentDay = new Date(year, month - 1);
|
||||||
|
console.log(currentDay);
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Seek
|
||||||
|
title={format(currentDay, "YYYY MMM")}
|
||||||
|
prev={format(subDays(currentDay, 1), "/YYYY/MM")}
|
||||||
|
next={"asdf"}
|
||||||
|
disableNext={isToday(new Date())}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default Month;
|
export default Month;
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import fire from "../../firebase/fire.js";
|
import fire from "../../firebase/fire.js";
|
||||||
|
|
||||||
|
import SignOut from "../../SignOut";
|
||||||
|
|
||||||
class User extends React.Component {
|
class User extends React.Component {
|
||||||
state = {
|
state = {
|
||||||
name: ""
|
name: ""
|
||||||
@@ -26,16 +28,19 @@ class User extends React.Component {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<form onSubmit={this.addUser}>
|
<React.Fragment>
|
||||||
<input
|
<SignOut />
|
||||||
type="text"
|
<form onSubmit={this.addUser}>
|
||||||
name="name"
|
<input
|
||||||
placeholder="Name"
|
type="text"
|
||||||
onChange={this.updateInput}
|
name="name"
|
||||||
value={this.state.name}
|
placeholder="Name"
|
||||||
/>
|
onChange={this.updateInput}
|
||||||
<button type="submit">Submit</button>
|
value={this.state.name}
|
||||||
</form>
|
/>
|
||||||
|
<button type="submit">Submit</button>
|
||||||
|
</form>
|
||||||
|
</React.Fragment>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { Component } from "react";
|
import React, { Component } from "react";
|
||||||
import isToday from "date-fns/is_today";
|
import { addYears, subYears, format } from "date-fns";
|
||||||
|
|
||||||
import Seek from "../../Seek";
|
import Seek from "../../Seek";
|
||||||
|
|
||||||
@@ -10,13 +10,15 @@ class Year extends Component {
|
|||||||
params: { year }
|
params: { year }
|
||||||
}
|
}
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
const currentDate = new Date(year, 0, 1);
|
||||||
|
console.log(currentDate.getFullYear());
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Seek
|
<Seek
|
||||||
title={year}
|
title={year}
|
||||||
prev={"Asdf"}
|
prev={format(subYears(currentDate, 1), "/YYYY")}
|
||||||
next={"asdf"}
|
next={format(addYears(currentDate, 1), "/YYYY")}
|
||||||
disableNext={isToday(new Date())}
|
disableNext={year >= new Date().getFullYear()}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
const theme = {
|
const theme = {
|
||||||
LIGHT: {
|
LIGHT: {
|
||||||
|
name: "Light",
|
||||||
colors: {
|
colors: {
|
||||||
primary: "#2E3136",
|
primary: "#2E3136",
|
||||||
secondary: "#999",
|
secondary: "#999",
|
||||||
@@ -11,6 +12,7 @@ const theme = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
DARK: {
|
DARK: {
|
||||||
|
name: "Dark",
|
||||||
colors: {
|
colors: {
|
||||||
primary: "#F3F6F8",
|
primary: "#F3F6F8",
|
||||||
secondary: "#9Ba3B0",
|
secondary: "#9Ba3B0",
|
||||||
|
|||||||
Reference in New Issue
Block a user