Skip to content

Commit

Permalink
created global store
Browse files Browse the repository at this point in the history
implemented DFPProvider for all pages
  • Loading branch information
oyilmaztekin committed Apr 5, 2019
1 parent a18d904 commit 0aa544a
Show file tree
Hide file tree
Showing 18 changed files with 172 additions and 103 deletions.
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"root": ["./"],
"alias": {
"@comp": "./components",
"@nest": "./nested",
"@nest":"./nested",
"@globalstyle": "./globalstyles/styles.scss",
"@mock": "./mocks",
"@static": "./static",
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ node_modules
.DS_Store
npm-debug.log
.netlify
.vscode/

# webpack output
.next/
Expand Down
3 changes: 2 additions & 1 deletion components/cards/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import "./assets/styles.scss";
class Cards extends Component {
constructor(props) {
super(props);
const items = this.props.registry.data.items[0];
this.state = {
limit: this.props.limit,
registry: this.props.registry,
catTitle: null,
catSlug: null,
isGallery: this.props.registry.data.items[0].type === "galeri"
isGallery: items && items.type && items.type === "galeri"
}
}

Expand Down
4 changes: 2 additions & 2 deletions components/infinite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import autobind from "autobind-decorator";
import { getDataset } from "@utils";
import { Block } from "@comp/layouts";
import ArticleHead from "@nest/articleheading";
import { URLConsumerHOC } from "@utils";
import { StoreConsumerHOC } from "@utils";

/**
* @this State
Expand Down Expand Up @@ -146,4 +146,4 @@ Infinite.defaultProps = {
dataset: "cat-gundem"
};

export default URLConsumerHOC(Infinite);
export default StoreConsumerHOC(Infinite);
38 changes: 34 additions & 4 deletions nested/catLayout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,31 @@ import Container from "@comp/container/";
import Row from "@comp/row/";
import Lists from "@comp/lists/";
import propTypes from "prop-types";
import {
DFPSlotsProvider,
AdSlot
} from "react-dfp";
import { StoreConsumerHOC } from "@utils";

const CategoryLayout = props => {
const {
context: {
state: { adNetworkID }
}
} = props;

return (
<Fragment>
<DFPSlotsProvider dfpNetworkId={adNetworkID}>
<AdSlot
sizes={[[970, 250]]}
adUnit={"AnasayfaMastHead"}
slotId="anasayfaMastHead"
/>
<AdSlot
sizes={[[160, 600], [120, 600]]}
adUnit={"anasayfa_sol1"}
slotId="anasayfa_sol"
/>
<Container
width={970}
className="section-cards"
Expand Down Expand Up @@ -78,13 +99,22 @@ const CategoryLayout = props => {
</Row>
</Container>
</Container>
</Fragment>
</DFPSlotsProvider>
);
};

CategoryLayout.propTypes = {
dataset: propTypes.object,
registry: propTypes.registry
registry: propTypes.registry,
context: propTypes.shape({
state: propTypes.shape({
activeURL: propTypes.string,
pageTitle: propTypes.string,
isHeaderSticky: propTypes.bool,
adNetworkID: propTypes.string,
updateValue: propTypes.func
})
})
};

export default CategoryLayout;
export default StoreConsumerHOC(CategoryLayout);
17 changes: 5 additions & 12 deletions nested/header/__tests__/header.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ describe("Header Component Testing", () => {
LogoImage="http://cdn.haberiyakala.com/assets/default/desktop/img/logo.png"
stickyClassName="orange-bg container"
navElements={mockData}
activeClass="sticky-now"
releasedClass="released"
/>
);
});
Expand All @@ -25,20 +27,11 @@ describe("Header Component Testing", () => {
debugger;
expect(
wrapper.children().get(0).props.activeClass
).toBe("active");
).toBe("sticky-now");
expect(
wrapper.children().get(0).props.className
wrapper.children().get(0).props.stickyClassName
).toBe("orange-bg container");
expect(
wrapper.children().get(0).props.enabled
).toBe(true);
expect(
wrapper.children().get(0).props
.onStateChange
).not.toBeUndefined();
expect(
wrapper.children().get(0).props.shouldFreeze
).not.toBeUndefined();

expect(
wrapper.children().get(0).props
.releasedClass
Expand Down
23 changes: 14 additions & 9 deletions nested/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import SearchForm from "@comp/searchform/";
import LinkButton from "@comp/linkButton/";
import Icon from "@comp/icon/";
import Container from "@comp/container/";
import { StoreConsumerHOC } from "@utils";

import {
faCamera,
Expand All @@ -24,18 +25,15 @@ class Header extends Component {
}
@autobind
handleStateChange(status) {
// FIXME: global state e bağla. burada değiştirmek doğru değil.
if (status.status === Sticky.STATUS_FIXED) {
console.log("the component is sticky");
const adLeft = document.getElementById("anasayfa_sol");
adLeft.style.top = 80 + "px";
if(status.status === 2) {
this.props.context.updateValue("isHeaderSticky", true)
}
else {
const adLeft = document.getElementById("anasayfa_sol");
adLeft.style.top = 150 + "px";
this.props.context.updateValue("isHeaderSticky", false)
}
}
render() {

let {
sticky,
top,
Expand Down Expand Up @@ -148,7 +146,14 @@ Header.propTypes = {
propTypes.number
]),
activeClass: propTypes.string,
releasedClass: propTypes.string
releasedClass: propTypes.string,
context: propTypes.shape({
activeURL: propTypes.string,
pageTitle: propTypes.string,
isHeaderSticky:propTypes.bool,
adNetworkID:propTypes.string,
updateValue:propTypes.func
})
};

export default Header;
export default StoreConsumerHOC(Header);
31 changes: 26 additions & 5 deletions nested/indexlayout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,21 @@ import Container from "@comp/container/";
import Row from "@comp/row/";
import Lists from "@comp/lists/";
import propTypes from "prop-types";
import { AdSlot } from "react-dfp";
import {
DFPSlotsProvider,
AdSlot
} from "react-dfp";
import { StoreConsumerHOC } from "@utils";

const IndexLayout = props => {
const {
context: {
state: { adNetworkID }
}
} = props;

return (
<Fragment>
<DFPSlotsProvider dfpNetworkId={adNetworkID}>
<AdSlot
sizes={[[970, 250]]}
adUnit={"AnasayfaMastHead"}
Expand Down Expand Up @@ -292,13 +302,24 @@ const IndexLayout = props => {
</Row>
</Container>
</Container>
</Fragment>
</DFPSlotsProvider>
);
};

IndexLayout.propTypes = {
dataset: propTypes.object,
registry: propTypes.registry
registry: propTypes.registry,
context: propTypes.shape({
state: propTypes.shape({
activeURL: propTypes.string,
pageTitle: propTypes.string,
isHeaderSticky: propTypes.bool,
adNetworkID: propTypes.string,
updateValue: propTypes.func
})
})
};

export default IndexLayout;
IndexLayout.displayName = "Index Layout"

export default StoreConsumerHOC(IndexLayout);
4 changes: 2 additions & 2 deletions nested/pagedetaillayout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Container from "@comp/container/";
import { Block } from "@comp/layouts";
import Breadcrumb from "@comp/breadcrumb";
import propTypes from "prop-types";
import { URLConsumerHOC } from "@utils";
import { StoreConsumerHOC } from "@utils";
import autobind from "autobind-decorator";

class PageDetailLayout extends Component {
Expand Down Expand Up @@ -94,4 +94,4 @@ PageDetailLayout.propTypes = {
context: propTypes.object
};

export default URLConsumerHOC(PageDetailLayout);
export default StoreConsumerHOC(PageDetailLayout);
21 changes: 10 additions & 11 deletions nested/pagelayout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,25 @@ import propTypes from "prop-types";
import ScrollToTop from "react-scroll-up";
import Icon from "@comp/icon/";
import { faArrowAltCircleUp } from "@fortawesome/free-solid-svg-icons";
import { URLProvider } from "@utils";
import { StoreProvider } from "@utils";
import { Block } from "@comp/layouts";

const PageLayout = props => {
return (
<Fragment>
<StoreProvider>
<Header
LogoImage="/static/logo.png"
navElements={mockData}
zIndex={9}
activeClass="sticky-now"
/>
<URLProvider>
<Block
type="section"
className="content-section"
>
{props.children}
</Block>
</URLProvider>

<Block
type="section"
className="content-section"
>
{props.children}
</Block>
<Footer />

<ScrollToTop showUnder={160}>
Expand All @@ -36,7 +35,7 @@ const PageLayout = props => {
/>
</span>
</ScrollToTop>
</Fragment>
</StoreProvider>
);
};

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"export": "next export",
"test": "jest --no-cache --verbose --coverage",
"test-debug": "/usr/local/bin/node --inspect-brk node_modules/jest/bin/jest.js --runInBand",
"test-debug-scope": "/usr/local/bin/node --inspect-brk node_modules/jest/bin/jest.js --runInBand linkbutton.test.js --testNamePattern='testing title and alt props'",
"test-debug-scope": "/usr/local/bin/node --inspect-brk node_modules/jest/bin/jest.js --runInBand header.test.js --testNamePattern='testing sticky header'",
"story": "start-storybook -p 6006",
"build-storybook": "build-storybook",
"lint": "esw ."
Expand Down Expand Up @@ -78,7 +78,7 @@
"@storybook/react": "^4.1.11",
"babel-eslint": "^10.0.1",
"babel-loader": "^8.0.5",
"babel-plugin-module-resolver": "^3.1.3",
"babel-plugin-module-resolver": "^3.2.0",
"enzyme": "^3.8.0",
"enzyme-adapter-react-16": "^1.9.1",
"eslint": "^4.19.1",
Expand Down
1 change: 1 addition & 0 deletions pages/gundem.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import PageLayout from "@nest/pagelayout";
import propTypes from "prop-types";
import CategoryLayout from "@nest/catLayout";
import "static/styles/pages.scss";
import "static/styles/indexAds.scss";

const GundemPage = props => {
return (
Expand Down
3 changes: 0 additions & 3 deletions pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@ import { getDataset, getContent } from "@utils";
import PageLayout from "@nest/pagelayout";
import propTypes from "prop-types";
import IndexLayout from "@nest/indexlayout";
import { DFPSlotsProvider, AdSlot } from "react-dfp";
import "static/styles/pages.scss";
import "static/styles/indexAds.scss";

const IndexPage = props => {
return (
<Fragment>
<PageLayout>
<DFPSlotsProvider dfpNetworkId="61966246">
<IndexLayout
registry={props.registry}
dataset={props.dataset}
/>
</DFPSlotsProvider>
</PageLayout>
</Fragment>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import React, { Component } from "react";
import { URLContext } from "@utils";
import { StoreContext } from "@utils";

export const URLConsumerHOC = WrappedComponent => {
export const StoreConsumerHOC = WrappedComponent => {
return class extends Component {
static displayName = WrappedComponent.displayName;
// eslint-disable-next-line
constructor(props) {
super(props);
}
render() {

return (
<URLContext.Consumer>
<StoreContext.Consumer>
{context => {
return <WrappedComponent {...this.props} context={context} />;
}}
</URLContext.Consumer>
</StoreContext.Consumer>
);
}
};
Expand Down
10 changes: 5 additions & 5 deletions utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ export {
} from "./axios/index";

export {
URLProvider,
URLContext
} from "./providers/urlprovider";
StoreProvider,
StoreContext
} from "./providers/storeprovider";

export {
URLConsumerHOC
} from "./consumers/urlconsumer";
StoreConsumerHOC
} from "./consumers/storeconsumer";

export { AdManager } from "./admanager";
Loading

0 comments on commit 0aa544a

Please sign in to comment.