Skip to content
Snippets Groups Projects
Commit 66a28801 authored by Santiago González's avatar Santiago González
Browse files

Header improvements. @observer implemented.

parent 8d3e09de
No related branches found
No related tags found
1 merge request!1Feature/course header
import * as React from "react"; import * as React from "react";
import styled from "styled-components"; import styled from "styled-components";
import { HSpacing } from "../../stylesheets/Mixins";
import { em } from "../../stylesheets/Units";
import { HeaderBase } from "./HeaderBase"; import { HeaderBase } from "./HeaderBase";
export class Header extends HeaderBase { export class Header extends HeaderBase {
protected Container = styled.div` protected Container = styled.div`
height: 100%; display: flex;
padding: 20px; align-items: center;
`; `;
protected Title = styled.div` protected Title = styled.div`
font-weight: bold; font-weight: bold;
font-size: 20px; font-size: 20px;
padding: 20px;
`; `;
public render() { public render() {
const { title } = this.props; const { title, button } = this.props;
const { Container, Title } = this; const { Container, Title } = this;
return ( return (
<Container> <Container>
{button}
<Title>{title}</Title> <Title>{title}</Title>
</Container> </Container>
); );
......
import * as React from "react";
import { import {
BaseComponent, BaseComponent,
BaseComponentProps, BaseComponentProps,
...@@ -6,6 +7,7 @@ import { ...@@ -6,6 +7,7 @@ import {
export interface HeaderBaseProps extends BaseComponentProps { export interface HeaderBaseProps extends BaseComponentProps {
title: string; title: string;
button?: React.ReactNode;
} }
export interface HeaderBaseState extends BaseComponentState {} export interface HeaderBaseState extends BaseComponentState {}
......
import * as _ from "lodash"; import * as _ from "lodash";
import * as React from "react"; import * as React from "react";
import styled, { css, keyframes } from "styled-components"; import styled, { css } from "styled-components";
import { observer } from "../../../node_modules/mobx-react";
import { LayoutOptions } from "../navigation/Layout"; import { LayoutOptions } from "../navigation/Layout";
import { WiderThan } from "../stylesheets/Mixins"; import { WiderThan } from "../stylesheets/Mixins";
import { Breakpoint } from "../stylesheets/Variables"; import { Breakpoint } from "../stylesheets/Variables";
...@@ -26,6 +27,7 @@ export interface DefaultLayoutProps< ...@@ -26,6 +27,7 @@ export interface DefaultLayoutProps<
export interface DefaultLayoutState extends LayoutBaseState {} export interface DefaultLayoutState extends LayoutBaseState {}
@observer
export class DefaultLayout< export class DefaultLayout<
P extends DefaultLayoutProps = DefaultLayoutProps, P extends DefaultLayoutProps = DefaultLayoutProps,
S extends DefaultLayoutState = DefaultLayoutState S extends DefaultLayoutState = DefaultLayoutState
...@@ -36,21 +38,21 @@ export class DefaultLayout< ...@@ -36,21 +38,21 @@ export class DefaultLayout<
display: flex; display: flex;
flex-direction: column; flex-direction: column;
${WiderThan( ${(p: { headerToShow: boolean }) =>
Breakpoint.medium, WiderThan(
css` Breakpoint.medium,
display: grid; css`
grid-template-rows: min-content auto; display: grid;
grid-template-columns: min-content auto; grid-template-rows: ${p.headerToShow ? "min-content" : "0"} auto;
` grid-template-columns: min-content auto;
)}; `
)};
`; `;
protected NavBarWrapper = styled.div` protected NavBarWrapper = styled.div`
box-shadow: 0px 0px 10px rgba(67, 52, 52, 0.4); box-shadow: 0px 0px 10px rgba(67, 52, 52, 0.4);
position: relative; position: relative;
width: 100%; width: 100%;
height: 100%;
${WiderThan( ${WiderThan(
Breakpoint.medium, Breakpoint.medium,
...@@ -114,8 +116,10 @@ export class DefaultLayout< ...@@ -114,8 +116,10 @@ export class DefaultLayout<
navBar = options.navOptions; navBar = options.navOptions;
} }
const headerToShow = !_.isNil(header) && !_.isNil(header.render);
return ( return (
<Container> <Container headerToShow={headerToShow}>
{!_.isNil(header) && {!_.isNil(header) &&
!_.isNil(header.render) && ( !_.isNil(header.render) && (
<HeaderWrapper <HeaderWrapper
......
...@@ -13,7 +13,7 @@ import { CourseBase } from "./CourseBase"; ...@@ -13,7 +13,7 @@ import { CourseBase } from "./CourseBase";
@observer @observer
export class Course extends CourseBase { export class Course extends CourseBase {
protected controls = { protected controls = {
container: React.createRef<HTMLDivElement>() classListWrapper: React.createRef<HTMLDivElement>()
}; };
protected prevScrollPos: number = 0; protected prevScrollPos: number = 0;
...@@ -21,11 +21,10 @@ export class Course extends CourseBase { ...@@ -21,11 +21,10 @@ export class Course extends CourseBase {
protected navBarMatches: boolean; protected navBarMatches: boolean;
protected Container = styled.div` protected Container = styled.div`
display: grid; display: flex;
flex-direction: column;
height: 100%; height: 100%;
width: 100%; width: 100%;
grid-template-columns: 100%;
grid-template-rows: fit-content(50%) auto;
min-height: 0; min-height: 0;
overflow: auto; overflow: auto;
grid-gap: 0; grid-gap: 0;
...@@ -34,6 +33,7 @@ export class Course extends CourseBase { ...@@ -34,6 +33,7 @@ export class Course extends CourseBase {
${WiderThan( ${WiderThan(
Breakpoint.small, Breakpoint.small,
css` css`
display: grid;
grid-template-columns: 350px auto; grid-template-columns: 350px auto;
grid-template-rows: auto auto auto; grid-template-rows: auto auto auto;
` `
...@@ -50,7 +50,7 @@ export class Course extends CourseBase { ...@@ -50,7 +50,7 @@ export class Course extends CourseBase {
protected ClassListWrapper = styled.div` protected ClassListWrapper = styled.div`
${List}; ${List};
height: initial; height: initial;
grid-row: 2 / 3; flex-grow: 1;
${WiderThan( ${WiderThan(
Breakpoint.small, Breakpoint.small,
...@@ -71,6 +71,7 @@ export class Course extends CourseBase { ...@@ -71,6 +71,7 @@ export class Course extends CourseBase {
align-items: center; align-items: center;
transition: max-height ease 0.5s; transition: max-height ease 0.5s;
max-height: 50%; max-height: 50%;
flex-shrink: 0;
${(p: { empty: boolean }) => ${(p: { empty: boolean }) =>
p.empty && p.empty &&
...@@ -96,22 +97,22 @@ export class Course extends CourseBase { ...@@ -96,22 +97,22 @@ export class Course extends CourseBase {
`; `;
public componentDidMount() { public componentDidMount() {
const { container } = this.controls; const { classListWrapper } = this.controls;
if (_.isNil(container.current)) { if (_.isNil(classListWrapper.current)) {
return; return;
} }
container.current.addEventListener("scroll", () => { classListWrapper.current.addEventListener("scroll", () => {
const layoutOptions = this.layoutOptions as Readonly< const layoutOptions = this.layoutOptions as Readonly<
DefaultLayoutOptions DefaultLayoutOptions
>; >;
if (_.isNil(container.current)) { if (_.isNil(classListWrapper.current)) {
return; return;
} }
const currentScrollPos = container.current.scrollTop; const currentScrollPos = classListWrapper.current.scrollTop;
if (this.prevScrollPos < currentScrollPos - 50) { if (this.prevScrollPos < currentScrollPos - 50) {
if ( if (
...@@ -203,14 +204,14 @@ export class Course extends CourseBase { ...@@ -203,14 +204,14 @@ export class Course extends CourseBase {
}} }}
</MediaQuery> */} </MediaQuery> */}
<Container innerRef={controls.container}> <Container>
<VideoWrapper empty={_.isNil(currentClass)}> <VideoWrapper empty={_.isNil(currentClass)}>
{!_.isNil(currentClass) && ( {!_.isNil(currentClass) && (
<CourseClassPlayer courseClass={currentClass} /> <CourseClassPlayer courseClass={currentClass} />
)} )}
</VideoWrapper> </VideoWrapper>
<ClassListWrapper> <ClassListWrapper innerRef={controls.classListWrapper}>
{!_.isNil(currentCourse.value) && {!_.isNil(currentCourse.value) &&
!_.isNil(currentCourse.value.classes) && !_.isNil(currentCourse.value.classes) &&
currentCourse.value.classes.map(clazz => ( currentCourse.value.classes.map(clazz => (
......
import * as _ from "lodash"; import * as _ from "lodash";
import { autorun } from "mobx"; import { autorun } from "mobx";
import * as React from "react"; import * as React from "react";
import { NavLink } from "react-router-dom";
import styled, { css } from "styled-components";
import { ClassesFetcher } from "../../actions/ClassesFetcher"; import { ClassesFetcher } from "../../actions/ClassesFetcher";
import { ClassSetter } from "../../actions/ClassSetter"; import { ClassSetter } from "../../actions/ClassSetter";
import { DocumentTitle } from "../../actions/DocumentTitle"; import { DocumentTitle } from "../../actions/DocumentTitle";
import { Header } from "../../components/header/Header"; import { Header } from "../../components/header/Header";
import { DefaultLayoutOptions } from "../../layout/DefaultLayout"; import { DefaultLayoutOptions } from "../../layout/DefaultLayout";
import { LayoutOptions } from "../../navigation/Layout"; import { LayoutOptions } from "../../navigation/Layout";
import { OnHover } from "../../stylesheets/Mixins";
import { BasePage, BasePageProps, BasePageState } from "../BasePage"; import { BasePage, BasePageProps, BasePageState } from "../BasePage";
export interface CourseMatchParams { export interface CourseMatchParams {
...@@ -38,6 +41,24 @@ export abstract class CourseBase< ...@@ -38,6 +41,24 @@ export abstract class CourseBase<
} }
}; };
protected NavButton = styled(NavLink).attrs({ activeClassName: "active" })`
position: relative;
background-color: transparent;
text-align: center;
text-decoration: none;
color: #000;
box-sizing: content-box;
padding: 20px;
${OnHover(css`
background-color: #eee;
`)};
> .la {
font-size: 1.5em;
}
`;
protected headerProps: CourseBaseHeaderProps = {}; protected headerProps: CourseBaseHeaderProps = {};
protected action = autorun(() => this.handleHeaderTitleChange()); protected action = autorun(() => this.handleHeaderTitleChange());
...@@ -48,7 +69,6 @@ export abstract class CourseBase< ...@@ -48,7 +69,6 @@ export abstract class CourseBase<
protected setHeaderTitle(title: string) { protected setHeaderTitle(title: string) {
const { headerProps } = this; const { headerProps } = this;
const { layoutOptions } = this;
if (headerProps.title !== title) { if (headerProps.title !== title) {
headerProps.title = title; headerProps.title = title;
...@@ -59,6 +79,11 @@ export abstract class CourseBase< ...@@ -59,6 +79,11 @@ export abstract class CourseBase<
<Header <Header
{...headerProps} {...headerProps}
title={headerProps.title || ""} title={headerProps.title || ""}
button={
<this.NavButton to="/" exact={true}>
<i className="la la-home" />
</this.NavButton>
}
/> />
) )
} }
......
import * as _ from "lodash"; import * as _ from "lodash";
import * as React from "react"; import * as React from "react";
import styled from "styled-components"; import styled from "styled-components";
import { observer } from "../../../../node_modules/mobx-react";
import { List } from "../../stylesheets/Mixins"; import { List } from "../../stylesheets/Mixins";
import { FAQItem } from "./faqitem/FAQItem"; import { FAQItem } from "./faqitem/FAQItem";
import { FAQsBase } from "./FAQsBase"; import { FAQsBase } from "./FAQsBase";
@observer
export class FAQs extends FAQsBase { export class FAQs extends FAQsBase {
protected Container = styled.div` protected Container = styled.div`
display: flex; display: flex;
......
import * as React from "react"; import * as React from "react";
import styled from "styled-components"; import styled from "styled-components";
import { NavBar } from "../../components/navbar/NavBar"; import { observer } from "../../../../node_modules/mobx-react";
import { DefaultLayout } from "../../layout/DefaultLayout";
import { LayoutOptions } from "../../navigation/Layout";
import { Grid } from "../../stylesheets/Mixins"; import { Grid } from "../../stylesheets/Mixins";
import { HomeBase } from "./HomeBase"; import { HomeBase } from "./HomeBase";
@observer
export class Home extends HomeBase { export class Home extends HomeBase {
protected Container = styled.div` protected Container = styled.div`
${Grid}; ${Grid};
grid-template-columns: auto fit-content(100%) auto; grid-template-columns: auto fit-content(100%) auto;
grid-template-rows: auto fit-content(100%) auto; grid-template-rows: auto fit-content(100%) auto;
height: 100%;
width: 100%;
`; `;
protected Image = styled.a` protected Image = styled.a`
......
import * as _ from "lodash"; import * as _ from "lodash";
import * as React from "react"; import * as React from "react";
import styled from "styled-components"; import styled from "styled-components";
import { observer } from "../../../../node_modules/mobx-react";
import { ResponsiveList } from "../../stylesheets/Mixins"; import { ResponsiveList } from "../../stylesheets/Mixins";
import { UpdateItem } from "./updateitem/UpdateItem"; import { UpdateItem } from "./updateitem/UpdateItem";
import { UpdatesBase } from "./UpdatesBase"; import { UpdatesBase } from "./UpdatesBase";
@observer
export class Updates extends UpdatesBase { export class Updates extends UpdatesBase {
protected UpdateList = styled.div` protected UpdateList = styled.div`
${ResponsiveList}; ${ResponsiveList};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment