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
const _cacheValues = new Map(); | |
const _cacheResolvedTime = new Map(); | |
const _cachePromises = new Map(); | |
const getDataCached = function (key) { | |
} |
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
function getData(key){ | |
return new Promise(function(resolve, reject) { | |
console.log('starting get ' + key) | |
setTimeout(() => { | |
console.log('ending get ' + key) | |
resolve(key); | |
}, 1000); | |
}) | |
} |
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
function wordCounter(input) { | |
const text = input.split(/\s+/) | |
let wordCount = 0 | |
for (let i = 0; i < text.length; i++) { | |
if (text[i] !== ' ' && isWord(text[i])) { | |
wordCount++ | |
} | |
} | |
return wordCount | |
} |
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
const wordsPerMinute = 225 | |
export function readingTime(text) { | |
return Math.ceil(wordCounter(text) / wordsPerMinute) | |
} |
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
const paginationHandler = (page) => { | |
const currentPath = props.router.pathname; | |
const currentQuery = props.router.query; | |
currentQuery.page = page.selected + 1; | |
props.router.push({ | |
pathname: currentPath, | |
query: currentQuery, | |
}) |
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
<ReactPaginate | |
previousLabel={'<'} | |
nextLabel={'>'} | |
breakLabel={'...'} | |
breakClassName={'break-me'} | |
activeClassName={'active'} | |
containerClassName={'pagination'} | |
subContainerClassName={'pages pagination'} | |
initialPage={props.currentPage - 1} | |
pageCount={props.pageCount} |
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
let content; | |
if (isLoading) { | |
content = ( | |
<div className={styles.loadWrapper}> | |
<Spinner animation="border" role="status"> | |
<span className="visually-hidden">Loading...</span> | |
</Spinner> | |
</div> | |
) | |
} else { |
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
const [isLoading, setLoading] = useState(false); | |
const startLoading = () => setLoading(true); | |
const stopLoading = () => setLoading(false); | |
useEffect(() => { | |
Router.events.on('routeChangeStart', startLoading); | |
Router.events.on('routeChangeComplete', stopLoading); | |
return () => { | |
Router.events.off('routeChangeStart', startLoading); |
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
const dev = process.env.NODE_ENV !== 'production'; | |
export const server = dev ? 'http://localhost:3000' : 'https://ppolivka.com'; |
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
Blog.getInitialProps = async ({ query }) => { | |
const page = query.page || 1; //if page empty we request the first page | |
const response = await fetch(`${server}/api/posts/${page}`) | |
const posts = await response.json() | |
return { | |
totalCount: posts.totalCount, | |
pageCount: posts.pageCount, | |
currentPage: posts.currentPage, | |
perPage: posts.perPage, | |
posts: posts.posts, |