generated from heshammourad/heroku-cra-node
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #296 from heshammourad/feature/content-db
Add static content component
- Loading branch information
Showing
17 changed files
with
130 additions
and
36 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import PropTypes from 'prop-types'; | ||
|
||
import HtmlWrapper from './HtmlWrapper'; | ||
import RedditMarkdown from './RedditMarkdown'; | ||
|
||
function FormattedContent({ className, content, markdown }) { | ||
return markdown ? ( | ||
<RedditMarkdown {...{ className, text: content }} /> | ||
) : ( | ||
<HtmlWrapper {...{ className, html: content }} /> | ||
); | ||
} | ||
|
||
FormattedContent.propTypes = { | ||
className: PropTypes.string, | ||
content: PropTypes.string.isRequired, | ||
markdown: PropTypes.bool, | ||
}; | ||
|
||
FormattedContent.defaultProps = { | ||
className: '', | ||
markdown: false, | ||
}; | ||
|
||
export default FormattedContent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import PropTypes from 'prop-types'; | ||
|
||
import useSwrStaticContent from '../data/useSwrStaticContent'; | ||
|
||
import FormattedContent from './FormattedContent'; | ||
|
||
/** | ||
* Renders static content from Firebase. | ||
* @param props | ||
* @param {string} [props.className] - Additional classes to apply. | ||
* @param {string} props.id - DB ID of static content. | ||
*/ | ||
function StaticContent({ className, id }) { | ||
const { data } = useSwrStaticContent(id); | ||
if (!data) { | ||
return null; | ||
} | ||
|
||
const { content, markdown } = data; | ||
|
||
return <FormattedContent {...{ className, content, markdown }} />; | ||
} | ||
|
||
StaticContent.propTypes = { | ||
className: PropTypes.string, | ||
id: PropTypes.string.isRequired, | ||
}; | ||
|
||
StaticContent.defaultProps = { | ||
className: undefined, | ||
}; | ||
|
||
export default StaticContent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import useSwrAuth from './useSwrAuth'; | ||
|
||
const useSwrStaticContent = (id) => useSwrAuth(`/staticContent/${id}`); | ||
|
||
export default useSwrStaticContent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const db = require('../db'); | ||
const { createLogger } = require('../logger'); | ||
|
||
const logger = createLogger('API/STATIC_CONTENT'); | ||
|
||
/** | ||
* Get static content from Firebase. | ||
* | ||
* @param {Object} req - Express request | ||
* @param {Object} req.params - Parameters on request | ||
* @param {string} req.params.id - DB id of static content to fetch | ||
* @param {*} res - Express response | ||
*/ | ||
exports.get = async ({ params: { id } }, res) => { | ||
try { | ||
const [result = {}] = await db.select( | ||
'SELECT content, markdown FROM static_content WHERE id = $1', | ||
[id], | ||
); | ||
const { content, markdown } = result; | ||
if (!content) { | ||
logger.info(`Static content with id='${id}' not found`); | ||
res.status(404).send(); | ||
} | ||
|
||
res.send({ content, markdown }); | ||
} catch (err) { | ||
logger.warn(`Error getting /${id}: ${err}`); | ||
res.status(500).send(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
The files in this directory are copies of the files that are stored in the static_content table in | ||
the database, placed here for reference. Best effort should be made to keep them in sync, but the | ||
database is the source of truth. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<ul> | ||
<li>Go through the submissions, and <strong>rate flags from 0-5</strong>. Feel encouraged to rate them all!</li> | ||
<li>A 0 would be a flag you think really misses the prompt or isn’t well executed, and a 5 is the best of the best.</li> | ||
<li>Vote on a <strong>good flag</strong>, not just a good image. Review the author’s description to understand their design. Click on a flag to view the description in the info panel.</li> | ||
<li><strong>Anonymity is key</strong> so revealing your flag while the contest is in session will result in a disqualification. After voting is over, anyone may claim their flags and we will announce the top 20 and update the <a href="http://www.reddit.com/r/vexillology/wiki/contests">yearly standings</a>.</li> | ||
</ul> |