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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #305 & #286 #375

Closed
wants to merge 54 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
72f9922
first commit
ProjGoodF May 23, 2019
e6ce205
Fixes 305
ProjGoodF May 23, 2019
baa3d82
Fixes 286
ProjGoodF May 23, 2019
d017c0e
bugs fixes
ProjGoodF May 23, 2019
3a5e42f
bugs fixes
ProjGoodF May 23, 2019
b55c2d5
adiitional fixes
ProjGoodF May 24, 2019
2b8c2e1
adiitional fixes
ProjGoodF May 24, 2019
7432342
adiitional fixes
ProjGoodF May 24, 2019
474defa
change preloader
ProjGoodF May 27, 2019
bd05481
305 additional changes
ProjGoodF May 31, 2019
c7c61d9
additional fixes
ProjGoodF May 31, 2019
935ecdc
additional fixes
ProjGoodF May 31, 2019
3eaf014
additional fixes
ProjGoodF May 31, 2019
753376a
Testing codeclimate integration
shcheklein Jun 2, 2019
dbca104
#286 fixes - restyling preloaders
ProjGoodF Jun 3, 2019
b793b3c
Merge remote-tracking branch 'origin/gf-fix_#305_2' into gf-fix_#305_2
ProjGoodF Jun 3, 2019
443c270
codeclimate integration fix
ProjGoodF Jun 3, 2019
3fc5709
codeclimate integration fix
ProjGoodF Jun 3, 2019
615feaa
codeclimate integration fix
ProjGoodF Jun 3, 2019
c5b4397
codeclimate integration fix
ProjGoodF Jun 3, 2019
fe6fd39
codeclimate integration fix
ProjGoodF Jun 3, 2019
a501545
codeclimate integration fix
ProjGoodF Jun 3, 2019
affe6ac
codeclimate integration fix
ProjGoodF Jun 3, 2019
2997f99
after command $ npx prettier --write "src/**"
ProjGoodF Jun 3, 2019
ceeee05
additional code-style fixes
ProjGoodF Jun 3, 2019
af5cbf7
SidebarMenu wraps revert
ProjGoodF Jun 3, 2019
e6f3d8b
temporarily disable file title requests
ProjGoodF Jun 4, 2019
f79399e
Merge branch 'master' into gf-fix_#305_2
ProjGoodF Jun 5, 2019
1b05319
master merge
ProjGoodF Jun 5, 2019
46ccf30
after master merge
ProjGoodF Jun 5, 2019
a7a1b27
after master merge
ProjGoodF Jun 5, 2019
744210f
after master merge
ProjGoodF Jun 5, 2019
56751ed
removed temporary comments in the code
ProjGoodF Jun 5, 2019
cc79225
resolve conflict
ProjGoodF Jun 5, 2019
792b74f
additional fixes
ProjGoodF Jun 6, 2019
b06ef3b
additional fixes
ProjGoodF Jun 6, 2019
4df194e
additional fixes (loadStateFromURL)
ProjGoodF Jun 7, 2019
fb1f9b7
additional fixes
ProjGoodF Jun 14, 2019
4c3b03d
rollback to working version
ProjGoodF Jun 19, 2019
dd8702b
code refactoring
ProjGoodF Jun 20, 2019
7c20072
add fixes
ProjGoodF Jun 21, 2019
34faa32
return PerfectScrollbar init
ProjGoodF Jun 21, 2019
ad9ec11
- сreated several helper functions in SideBarMenuHelper and introduce…
ProjGoodF Jun 27, 2019
a6b2f46
resolve conflicts
ProjGoodF Jun 27, 2019
f62326d
replace functions not directly related to doc.js inside helper
ProjGoodF Jul 1, 2019
129b512
additional fixes by last review comments
ProjGoodF Jul 1, 2019
386ad4c
additional fixes by last review comments
ProjGoodF Jul 2, 2019
207e286
completed functions flagged as "//done",
ProjGoodF Jul 9, 2019
524c638
additional changes
ProjGoodF Jul 10, 2019
dad0bc1
additional changes
ProjGoodF Jul 10, 2019
594f0a6
95% complete
ProjGoodF Jul 11, 2019
0dc7f16
in an attempt to solve the page reload problem
ProjGoodF Jul 12, 2019
93e86ad
SideHelper.getFile() problem solving in the process
ProjGoodF Jul 15, 2019
1080df4
SideHelper.getFile() problem solving in the process
ProjGoodF Jul 16, 2019
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
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

154 changes: 96 additions & 58 deletions pages/doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export default class Documentation extends Component {
markdown: '',
headings: [],
pageNotFound: false,
isMenuOpen: false
isMenuOpen: false,
load: false
}
}

Expand All @@ -55,35 +56,69 @@ export default class Documentation extends Component {
}

loadStateFromURL = () => {
const { pathname } = window.location
const sectionURL = pathname.split('/')[2] // match section from URL
const sectionIndex = sidebar.findIndex(
section => (section.slug || kebabCase(section.name)) === sectionURL
)
const { pathname } = window.location;
shcheklein marked this conversation as resolved.
Show resolved Hide resolved
const sectionURL = pathname.split('/')[2];
const sectionIndex = sectionURL ? sidebar.findIndex(
section => kebabCase(section.name) === sectionURL
) : 0;
if (sectionIndex === -1) {
sectionURL
? this.setState({ pageNotFound: true })
: this.onSectionSelect(0)
this.setState({ pageNotFound: true })
} else {
const fileURL = pathname.split('/')[3] // match file from URL
const sectionFiles = flatten(sidebar[sectionIndex].files)
const fileIndex = sectionFiles.findIndex(
file => kebabCase(file.slice(0, -3)) === fileURL
)
if (fileIndex === -1) {
fileURL
? this.setState({ pageNotFound: true })
: this.onSectionSelect(sectionIndex)
} else {
this.loadFile({
section: sectionIndex,
file: sectionFiles[fileIndex],
parseHeadings: true,
pageNotFound: false
})
const fileURL = pathname.split('/')[3]; // match file from URL
const section = sidebar[sectionIndex];
if(fileURL){
if(pathname.split('/')[4]){
ProjGoodF marked this conversation as resolved.
Show resolved Hide resolved
let subsectionIndex = section.files.findIndex(
file => kebabCase(file.indexFile.slice(0, -3)) === fileURL
);
let fileIndex = section.files[subsectionIndex].files.findIndex(
file => kebabCase(file.indexFile.slice(0, -3)) === pathname.split('/')[4]
);
this.loadFile({
file: section.files[subsectionIndex].files[fileIndex],
section: sectionIndex,
parseHeadings: true,
})
}else{
let fileIndex = section.files.findIndex(
file => kebabCase(file.indexFile.slice(0, -3)) === fileURL
);
if (fileIndex === -1) {
let fileIndex2=-1, subsectionIndex=0;
section.files.map((subsection,index2)=>{
if (subsection.files.length>0){
fileIndex2 = subsection.files.findIndex(
file2 => {
if(kebabCase(file2.indexFile.slice(0, -3)) === fileURL){
subsectionIndex = index2;
}
return kebabCase(file2.indexFile.slice(0, -3)) === fileURL
}
);
}
});
if (fileIndex2 === -1){
fileURL ? this.setState({ pageNotFound: true }) : this.onSectionSelect(sectionIndex)
}else{
this.loadFile({
file: section.files[subsectionIndex].files[fileIndex2],
section: sectionIndex,
parseHeadings: true,
})
}
}else{
this.loadFile({
file: section.files[fileIndex],
section: sectionIndex,
parseHeadings: true,
})
}
}
}else{
this.loadFile({ file:section.hasOwnProperty('indexFile') ? section : section.files[0], section: sectionIndex, parseHeadings: false });
}
}
}
};

initDocsearch = () => {
docsearch({
Expand All @@ -92,45 +127,46 @@ export default class Documentation extends Component {
inputSelector: '#doc-search',
debug: false // Set debug to true if you want to inspect the dropdown
})
}
};

getLinkHref = (section, file) => {
const sectionSlug =
sidebar[section].slug || kebabCase(sidebar[section].name)
const fileSlug = file ? kebabCase(file.slice(0, -3)) : undefined
return `/doc/${compact([sectionSlug, fileSlug]).join('/')}`
}
getLinkHref = (section, file, subsection=null) => {
const sectionSlug = kebabCase(sidebar[section].name);
const fileSlug = file ? file.slice(0, -3) : undefined;
let subsectionSlug = subsection ? sidebar[section].files[subsection].indexFile.slice(0,-3) : '';
return `/doc/${compact([sectionSlug, subsectionSlug, fileSlug]).join('/')}`;
};

setCurrentPath = (section, file) => {
window.history.pushState(null, null, this.getLinkHref(section, file))
}
setCurrentPath = (section, file, subsection) => {
window.history.pushState(null, null, this.getLinkHref(section, file, subsection))
};

onSectionSelect = (section, e) => {
e && e.preventDefault()
const { indexFile, files } = sidebar[section]
const file = indexFile || flatten(files)[0]
e && this.setCurrentPath(section, indexFile ? undefined : file)
this.loadFile({ file, section, parseHeadings: false })
}

onFileSelect = (file, section, e) => {
e && e.preventDefault()
this.setCurrentPath(section, file)
this.loadFile({ file, section, parseHeadings: true })
}
e && e.preventDefault();
const file = sidebar[section].hasOwnProperty('indexFile') ? sidebar[section] : sidebar[section].files[0];
e && this.setCurrentPath(section);
this.loadFile({ file, section, parseHeadings: false });
};

onFileSelect = (file, section, e, subsection) => {
e && e.preventDefault();
this.setCurrentPath(section, file.indexFile, subsection);
this.loadFile({ file, section, parseHeadings: true });
};

loadFile = ({ file, section, parseHeadings }) => {
fetch(`${sidebar[section].folder}/${file}`)
this.setState({load:true});
fetch(`${file.folder}/${file.indexFile}`)
.then(res => {
res.text().then(text => {
this.setState(
{
currentSection: section,
currentFile: file,
currentFile: file.indexFile,
markdown: text,
headings: [],
pageNotFound: false,
isMenuOpen: false
isMenuOpen: false,
load: false
},
() => {
this.scrollTop()
Expand Down Expand Up @@ -198,7 +234,8 @@ export default class Documentation extends Component {
headings,
markdown,
pageNotFound,
isMenuOpen
isMenuOpen,
load
} = this.state

const directory = sidebar[currentSection].folder
Expand Down Expand Up @@ -240,6 +277,7 @@ export default class Documentation extends Component {
githubLink={githubLink}
section={currentSection}
file={currentFile}
load={load}
onFileSelect={this.onFileSelect}
/>
)}
Expand Down Expand Up @@ -286,8 +324,8 @@ const Backdrop = styled.div`
transition: opacity .3s linear;

${props =>
props.visible &&
`
props.visible &&
`
content: '';
position: fixed;
top: 0;
Expand Down Expand Up @@ -323,8 +361,8 @@ const Side = styled.div`
transition: transform .35s ease;

${props =>
props.isOpen &&
`
props.isOpen &&
`
transform: translateX(0);
`}
`};
Expand Down Expand Up @@ -373,8 +411,8 @@ const SideToggle = styled.div`
`};

${({ isMenuOpen }) =>
isMenuOpen &&
`
isMenuOpen &&
`
transform: translateX(calc(100vw - 60px));
`};
`
80 changes: 44 additions & 36 deletions src/Documentation/Markdown/Markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,47 +127,55 @@ export default class Markdown extends Component {
}

render() {
const { markdown, githubLink, section, file, onFileSelect } = this.props
const { markdown, githubLink, section, file, onFileSelect, load } = this.props
const files = sidebar[section].files
const fileIndex = files.findIndex(f => f === file)
const showPrev = fileIndex > 0
const showNext = fileIndex + 1 < sidebar[section].files.length

return (
<Content>
<GithubLink href={githubLink} target="_blank">
<i /> Edit on Github
</GithubLink>
<ReactMarkdown
key={`${section}-${fileIndex}`}
className="markdown-body"
escapeHtml={false}
source={markdown}
renderers={{
code: CodeBlock,
heading: HeadingRenderer,
virtualHtml: HtmlRenderer
}}
astPlugins={[linker()]}
/>
<NavigationButtons>
<Button
onClick={() => onFileSelect(files[fileIndex - 1], section)}
disabled={!showPrev}
>
<i className="prev" />
<span>Prev</span>
</Button>
<Button
onClick={() => onFileSelect(files[fileIndex + 1], section)}
disabled={!showNext}
>
<span>Next</span>
<i className="next" />
</Button>
</NavigationButtons>
</Content>
)
if(load){
return(
<Content>
<p>Loading...</p>
</Content>
)
}else{
return (
<Content>
<GithubLink href={githubLink} target="_blank">
<i /> Edit on Github
</GithubLink>
<ReactMarkdown
key={`${section}-${fileIndex}`}
className="markdown-body"
escapeHtml={false}
source={markdown}
renderers={{
code: CodeBlock,
heading: HeadingRenderer,
virtualHtml: HtmlRenderer
}}
astPlugins={[linker()]}
/>
<NavigationButtons>
<Button
onClick={() => onFileSelect(files[fileIndex - 1], section)}
disabled={!showPrev}
>
<i className="prev" />
<span>Prev</span>
</Button>
<Button
onClick={() => onFileSelect(files[fileIndex + 1], section)}
disabled={!showNext}
>
<span>Next</span>
<i className="next" />
</Button>
</NavigationButtons>
</Content>
)
}
}
}

Expand Down
Loading