Skip to content
Draft

Leagcy #1147

Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix: edit links for api and advanced pages (#842)
  • Loading branch information
griimick authored Oct 8, 2022
commit 803b6a4fb6d32ae644fb305c9856eb8b1b842969
7 changes: 6 additions & 1 deletion src/components/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const Layout = (props: {
const { currentLanguage } =
language && language.currentLanguage ? language : { currentLanguage: "en" }
const lightMode = state?.setting?.lightMode
const currentVersion = state?.setting?.version
const [show, setShow] = React.useState(false)
const scrollHandler = () => {
if (window.scrollY > 75) {
Expand All @@ -30,7 +31,11 @@ const Layout = (props: {
setShow(false)
}
}
const editLink = getEditLink(currentLanguage, props.location?.pathname)
const editLink = getEditLink(
currentVersion,
currentLanguage,
props.location?.pathname
)

React.useEffect(() => {
window.addEventListener("scroll", scrollHandler)
Expand Down
15 changes: 12 additions & 3 deletions src/components/logic/getEditLink.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
const preFix =
"https://github.com/react-hook-form/documentation/edit/master/src/data/"
"https://github.com/react-hook-form/documentation/edit/v6-v5/src/data/"

export const getEditLink = (
currentVersion: number,
currentLanguage: string,
pathname: string
): string => {
if (!pathname) return ""

let versionTag = ""
if (currentVersion === 6) {
versionTag = "V6/"
} else if (currentVersion === 5) {
versionTag = "V5/"
}

if (pathname === "/" || pathname === "") {
return preFix + "home.tsx"
} else if (pathname.includes("get-started")) {
return `${preFix}${currentLanguage}/getStarted.tsx`
} else if (pathname.includes("api")) {
return `${preFix}${currentLanguage}/api.tsx`
return `${preFix}${versionTag}${currentLanguage}/api.tsx`
} else if (pathname.includes("ts")) {
return `${preFix}ts.tsx`
} else if (pathname.includes("advanced-usage")) {
return `${preFix}${currentLanguage}/advanced.tsx`
const tag = currentVersion < 7 && currentLanguage === "en" ? "V6/" : ""
return `${preFix}${tag}${currentLanguage}/advanced.tsx`
} else if (pathname.includes("faqs")) {
return `${preFix}${currentLanguage}/faq.tsx`
} else if (pathname.includes("dev-tools")) {
Expand Down