Skip to content
This repository was archived by the owner on Dec 24, 2020. It is now read-only.

Commit 370eddd

Browse files
finishing touches (#1)
- Documentation - Finish example app - Small tweaks Co-authored-by: Julian Rubisch <julian@julianrubisch.at>
1 parent 826f494 commit 370eddd

File tree

13 files changed

+321
-38
lines changed

13 files changed

+321
-38
lines changed

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
12.13.0

CODE_OF_CONDUCT.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as
6+
contributors and maintainers pledge to making participation in our project and
7+
our community a harassment-free experience for everyone, regardless of age, body
8+
size, disability, ethnicity, sex characteristics, gender identity and expression,
9+
level of experience, education, socio-economic status, nationality, personal
10+
appearance, race, religion, or sexual identity and orientation.
11+
12+
## Our Standards
13+
14+
Examples of behavior that contributes to creating a positive environment
15+
include:
16+
17+
* Using welcoming and inclusive language
18+
* Being respectful of differing viewpoints and experiences
19+
* Gracefully accepting constructive criticism
20+
* Focusing on what is best for the community
21+
* Showing empathy towards other community members
22+
23+
Examples of unacceptable behavior by participants include:
24+
25+
* The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
* Trolling, insulting/derogatory comments, and personal or political attacks
28+
* Public or private harassment
29+
* Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
* Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
33+
34+
## Our Responsibilities
35+
36+
Project maintainers are responsible for clarifying the standards of acceptable
37+
behavior and are expected to take appropriate and fair corrective action in
38+
response to any instances of unacceptable behavior.
39+
40+
Project maintainers have the right and responsibility to remove, edit, or
41+
reject comments, commits, code, wiki edits, issues, and other contributions
42+
that are not aligned to this Code of Conduct, or to ban temporarily or
43+
permanently any contributor for other behaviors that they deem inappropriate,
44+
threatening, offensive, or harmful.
45+
46+
## Scope
47+
48+
This Code of Conduct applies both within project spaces and in public spaces
49+
when an individual is representing the project or its community. Examples of
50+
representing a project or community include using an official project e-mail
51+
address, posting via an official social media account, or acting as an appointed
52+
representative at an online or offline event. Representation of a project may be
53+
further defined and clarified by project maintainers.
54+
55+
## Enforcement
56+
57+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
58+
reported by contacting the project team at andrewmcodes@protonmail.com. All
59+
complaints will be reviewed and investigated and will result in a response that
60+
is deemed necessary and appropriate to the circumstances. The project team is
61+
obligated to maintain confidentiality with regard to the reporter of an incident.
62+
Further details of specific enforcement policies may be posted separately.
63+
64+
Project maintainers who do not follow or enforce the Code of Conduct in good
65+
faith may face temporary or permanent repercussions as determined by other
66+
members of the project's leadership.
67+
68+
## Attribution
69+
70+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72+
73+
[homepage]: https://www.contributor-covenant.org
74+
75+
For answers to common questions about this code of conduct, see
76+
https://www.contributor-covenant.org/faq

CONTRIBUTING.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Contributing
2+
3+
[code-of-conduct]: CODE_OF_CONDUCT.md
4+
5+
Hey, there! 👋 Any and all contributions are welcome.
6+
7+
Please make sure to read the [code of conduct][code-of-conduct] before submitting issues or pull requests.
8+
9+
To lend a helping hand:
10+
* [Fork the repository](https://help.github.com/articles/fork-a-repo/)
11+
* Make your desired changes
12+
* [Create a pull request](https://help.github.com/articles/creating-a-pull-request/)

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Andrew Mason
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 106 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,129 @@
1+
[CoC]: /CODE_OF_CONDUCT.md
2+
[contributing]: /CONTRIBUTING.md
3+
[license]: /LICENSE
4+
15
# @codefund/react-api-hook
26
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
37
[![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg?style=flat-square)](#contributors-)
48
<!-- ALL-CONTRIBUTORS-BADGE:END -->
59

6-
> CodeFund.io API hook for React.js
10+
[![NPM](https://img.shields.io/npm/v/@codefund/react-api-hook.svg)](https://www.npmjs.com/package/@codefund/react-api-hook)
711

8-
[![NPM](https://img.shields.io/npm/v/@codefund/react-api-hook.svg)](https://www.npmjs.com/package/@codefund/react-api-hook) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
12+
> CodeFund.io API hook for React.js
913
1014
## Install
1115

1216
```bash
17+
# NPM
1318
npm install --save @codefund/react-api-hook
19+
20+
# Yarn
21+
yarn add @codefund/react-api-hook
1422
```
1523

1624
## Usage
1725

18-
TODO
19-
<!--
20-
```tsx
21-
import * as React from 'react'
26+
All you need to do is pass your CodeFund Property ID to the hook and save the ad markup to a variable:
27+
28+
```js
29+
const { ad } = useCodeFundAd(process.env.REACT_APP_CODEFUND_PROPERTY_ID)
30+
```
31+
32+
The hook will return three values if you'd like to use them, but `ad` is the only necessary value.
33+
34+
Note that we only return an ad when your `NODE_ENV` is production.
35+
36+
### `ad: string`
37+
38+
The markup for the ad that you can then render on a page.
39+
40+
<details>
41+
<summary>Example Return Value</summary>
2242

23-
import { useMyHook } from '@codefund/react-api-hook'
43+
```html
44+
<link href="https://app.codefund.io/packs/css/code_fund_ad-a247634a.css" rel="stylesheet" media="all"><div id="cf" data-template="default" data-theme="light"> <span> <span class="cf-wrapper"> <a href="https://app.codefund.io/impressions/654962e7-a2b0-40a5-9419-96d372c879cc/click?campaign_id=635&amp;creative_id=580&amp;property_id=669&amp;template=default&amp;theme=light" class="cf-sponsored-by" target="_blank" rel="sponsored noopener"> <span class="cf-img-wrapper"> <img src="https://cdn2.codefund.app/1dipzax8qeezdz49lasl7abpbkao" alt="Sell Out Ethically" border="0" height="100" width="130" class="cf-img"> </span> <span class="cf-text"> <strong>Earn money without selling out.</strong> <span>Consider placing ethical ads on your site.</span> </span> </a> <a href="https://app.codefund.io/invite/4nr1oPkB4W8" class="cf-powered-by" target="_blank" rel="sponsored noopener"> <em>ethical</em> ad by CodeFund <img src="https://app.codefund.io/display/654962e7-a2b0-40a5-9419-96d372c879cc.gif" data-src="https://app.codefund.io/display/654962e7-a2b0-40a5-9419-96d372c879cc.gif" data-behavior="trackImpression" class="cf-impression" alt=""> </a> </span> </span> </div>
45+
```
2446

25-
const Example = () => {
26-
const example = useMyHook()
27-
return (
28-
<div>
29-
{example}
30-
</div>
31-
)
47+
</details>
48+
49+
### `loading: boolean`
50+
51+
A boolean value indicating whether the ad is in a loading state or not. You can use this to create a nice loading or skeleton effect, which you can see in the example app.
52+
53+
### `error: string`
54+
55+
A string value that holds the response message from the fetch request in the event the request returns a non-200 response code.
56+
57+
## Basic Example
58+
59+
```js
60+
import React from "react"
61+
import { useCodeFundAd } from "@codefund/react-api-hook"
62+
63+
const App = () => {
64+
const { ad } = useCodeFundAd(process.env.REACT_APP_CODEFUND_PROPERTY_ID)
65+
return <Ad ad={ad} />
3266
}
33-
``` -->
67+
68+
const Ad = ({ ad }) => (
69+
<div dangerouslySetInnerHTML={{ __html: ad }} />
70+
)
71+
72+
export default App
73+
```
74+
75+
## Advanced Example
76+
77+
```js
78+
import React from "react"
79+
import Skeleton from "react-skeleton-loader"
80+
import { useCodeFundAd } from "@codefund/react-api-hook"
81+
82+
class App extends React.Component {
83+
render () {
84+
return <CodeFund />
85+
}
86+
}
87+
88+
function CodeFund () {
89+
const { ad, loading, error } = useCodeFundAd(process.env.REACT_APP_CODEFUND_PROPERTY_ID)
90+
if (loading) {
91+
return <AdLoading />
92+
}
93+
94+
if (!error) {
95+
return <AdMarkup ad={ad} />
96+
}
97+
}
98+
99+
function AdMarkup (props) {
100+
return <div dangerouslySetInnerHTML={{ __html: props.ad }} />
101+
}
102+
103+
function AdLoading () {
104+
return <Skeleton count={5} width={"330px"} borderRadius={"0px"} />
105+
}
106+
107+
export default App
108+
```
109+
110+
## Contributing
111+
112+
We encourage you to contribute! Please check out the [Contributing Guide][contributing] for guidelines about how to proceed.
113+
114+
### Code of Conduct
115+
116+
Everyone interacting with the project’s codebase and issue tracker are expected to follow the [Code of Conduct][CoC].
117+
118+
### Coding Standards
119+
120+
This project uses Prettier for JavaScript code to minimize bike shedding related to source formatting.
121+
122+
Please run `yarn format` prior to submitting pull requests.
34123

35124
## License
36125

37-
MIT © [andrewmcodes](https://github.com/andrewmcodes)
126+
Released under the [MIT License][license].
38127

39128
## Contributors ✨
40129

@@ -54,4 +143,4 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
54143
<!-- prettier-ignore-end -->
55144
<!-- ALL-CONTRIBUTORS-LIST:END -->
56145

57-
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
146+
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!

example/.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SKIP_PREFLIGHT_CHECK=true
2+
REACT_APP_CODEFUND_PROPERTY_ID=0

example/.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
12.13.0

example/.prettierrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"semi": false,
3+
"singleQuote": false,
4+
"tabWidth": 2,
5+
"trailingComma": "es5"
6+
}

example/package.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
11
{
22
"name": "@codefund/react-api-hook-example",
33
"homepage": "https://andrewmcodes.github.io/codefund-react-api-hook",
4-
"version": "0.0.0",
4+
"version": "0.0.1",
55
"license": "MIT",
66
"private": true,
77
"dependencies": {
8+
"@codefund/react-api-hook": "link:..",
89
"react": "link:../node_modules/react",
910
"react-dom": "^16.9.0",
11+
"react-lorem-ipsum": "^1.4.4",
1012
"react-scripts": "^3.0.1",
11-
"@codefund/react-api-hook": "link:.."
13+
"react-skeleton-loader": "^1.0.4"
1214
},
1315
"scripts": {
1416
"start": "react-scripts start",
1517
"build": "react-scripts build",
1618
"test": "react-scripts test --env=jsdom",
17-
"eject": "react-scripts eject"
19+
"eject": "react-scripts eject",
20+
"format": "prettier --write \"src/**/*\""
1821
},
1922
"browserslist": [
2023
">0.2%",
2124
"not dead",
2225
"not ie <= 11",
2326
"not op_mini all"
24-
]
27+
],
28+
"devDependencies": {
29+
"prettier": "^1.19.1"
30+
}
2531
}

example/src/App.js

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,50 @@
1-
import React from 'react'
2-
import { useCodeFundAd } from '@codefund/react-api-hook'
1+
import React from "react"
2+
import Skeleton from "react-skeleton-loader"
3+
import { LoremIpsum } from "react-lorem-ipsum"
4+
import { useCodeFundAd } from "@codefund/react-api-hook"
35

4-
// TODO
5-
const App = () => {
6-
const { ad, loading, error } = useCodeFundAd('0')
7-
return <Ad adMarkup={ad} loadingState={loading} errorMessage={error} />
6+
class App extends React.Component {
7+
render() {
8+
return (
9+
<>
10+
<h1>@codefund/react-api-hook Demo</h1>
11+
<Text paragraphs={2} />
12+
<div className="center">
13+
<CodeFund />
14+
</div>
15+
<Text paragraphs={6} />
16+
</>
17+
)
18+
}
819
}
920

10-
const Ad = ({ adMarkup, loadingState, errorMessage }) => <div dangerouslySetInnerHTML={adMarkup} />
21+
function CodeFund() {
22+
const { ad, loading, error } = useCodeFundAd(
23+
process.env.REACT_APP_CODEFUND_PROPERTY_ID
24+
)
25+
if (loading) {
26+
return <AdLoading />
27+
}
28+
29+
if (!error) {
30+
return <AdMarkup ad={ad} />
31+
}
32+
}
33+
34+
function AdMarkup(props) {
35+
return <div dangerouslySetInnerHTML={{ __html: props.ad }} />
36+
}
37+
38+
function AdLoading() {
39+
return <Skeleton count={5} width={"330px"} borderRadius={"0px"} />
40+
}
41+
42+
function Text(props) {
43+
return (
44+
<div className="text-wrapper">
45+
<LoremIpsum p={props.paragraphs} avgSentencesPerParagraph={16} />
46+
</div>
47+
)
48+
}
1149

1250
export default App

example/src/index.css

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
1-
/* body {
2-
margin: 0;
3-
padding: 0;
4-
font-family: sans-serif;
5-
} */
1+
html {
2+
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto,
3+
Helvetica Neue, Arial, Noto Sans, sans-serif, Apple Color Emoji,
4+
Segoe UI Emoji, Segoe UI Symbol, Noto Color Emoji;
5+
line-height: 1.5;
6+
font-size: 14px;
7+
}
8+
9+
body {
10+
padding: 2em;
11+
}
12+
13+
p {
14+
font-size: 1.125rem;
15+
}
16+
17+
.center {
18+
display: flex;
19+
align-items: center;
20+
justify-content: center;
21+
}

0 commit comments

Comments
 (0)