Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Legacy #839

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/ApiErrors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default React.memo(
errors:{" "}
<span
className={typographyStyles.typeText}
>{`Record<string, Object>`}</span>
>{`Record<string, object>`}</span>
</h2>
</code>

Expand Down
2 changes: 1 addition & 1 deletion src/components/ApiWatch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export default function ApiWatch({
<code>watch('inputName')</code>
</td>
<td>
<code className={typographyStyles.typeText}>unkown</code>
<code className={typographyStyles.typeText}>unknown</code>
</td>
</tr>
<tr>
Expand Down
2 changes: 1 addition & 1 deletion src/components/UseWatchContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export default function UseFieldArray({
<code>useWatch('inputName')</code>
</td>
<td>
<code className={typographyStyles.typeText}>unkown</code>
<code className={typographyStyles.typeText}>unknown</code>
</td>
</tr>
<tr>
Expand Down
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