Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Hotfix/383 update todos #949

Merged
merged 6 commits into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions components/atoms/ExitPreview/ExitPreview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Link from 'next/link'

/**
* Renders an anchor to exit Preview Mode.
*
* @param {object} props The component as props.
* @param {object} props.preview Checks if a preview exists.
* @return {Element | null} The ExitPreview component.
*/
export default function ExitPreview({preview}) {
if (preview) {
return (
<p>
This page is a preview.
<Link href="/api/exit-preview">
<a>Exit preview mode</a>
</Link>
</p>
)
}

return null
}
1 change: 1 addition & 0 deletions components/atoms/ExitPreview/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {default} from './ExitPreview.js'
22 changes: 5 additions & 17 deletions functions/isLinkActive.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,10 @@ export default function isLinkActive(asPath, path) {
return false
}

// TODO: Add functionality to check if link is in the full URL path.
// e.g. /portfolio /portfolio/cambells-soup

return asPath === stripTrailingSlash(path)
}

/**
* Remove the last trailing slash from a URL path.
*
* @author WebDevStudios
* @param {string} str The string to search and remove trailing slash.
* @return {string} The formatted string.
*/
function stripTrailingSlash(str) {
if (str.substr(-1) === '/' && str.length > 1) {
return str.substr(0, str.length - 1)
if (path.length > 1) {
const checkSubStr = new RegExp(path)
return checkSubStr.test(asPath)
}
return str

return path === asPath
}
Loading