forked from kruzhok-team/lapki-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kruzhok-team#95 from Roundabout1/server_button_set…
…tings Вывести адрес компилятора и доксервера в настройки (electron-settings)
- Loading branch information
Showing
20 changed files
with
655 additions
and
434 deletions.
There are no files selected for viewing
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
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
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
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
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
237 changes: 126 additions & 111 deletions
237
src/renderer/src/components/Documentation/Documentation.tsx
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,111 +1,126 @@ | ||
import { useState, useEffect } from 'react'; | ||
import { twMerge } from 'tailwind-merge'; | ||
|
||
import { Tree } from './components/Tree'; | ||
import Show from './components/Show'; | ||
|
||
import { ReactComponent as Arrow } from '@renderer/assets/icons/arrow.svg'; | ||
import { useDoc } from '@renderer/store/useDoc'; | ||
|
||
/*Загрузка документации*/ | ||
|
||
interface DocumentationsProps { | ||
baseUrl: string; | ||
topOffset?: boolean; | ||
} | ||
|
||
export function Documentations({ baseUrl, topOffset = false }: DocumentationsProps) { | ||
const [activeTab, setActiveTab] = useState<number>(0); | ||
const [data, setData] = useState<{ body: File }>(); | ||
const [html, setHtml] = useState(''); | ||
const [documentLink, setDocumentLink] = useState(''); | ||
|
||
const [isOpen, toggle] = useDoc((state) => [state.isOpen, state.toggle]); | ||
|
||
const getData = () => { | ||
fetch(baseUrl) | ||
.then((data) => data.json()) | ||
.then((data) => { | ||
setData(data); | ||
}); | ||
}; | ||
|
||
const onItemClicked = (event: React.MouseEvent<HTMLLIElement, MouseEvent>, item) => { | ||
event.stopPropagation(); | ||
if (item.path.endsWith('html')) { | ||
fetch(encodeURI(`${baseUrl}${item.path}`)) | ||
.then((data) => data.text()) | ||
.then((html) => { | ||
setHtml(html); | ||
setActiveTab(1); | ||
}); | ||
} else { | ||
setHtml(''); | ||
setDocumentLink(`${baseUrl}${item.path}`); | ||
setActiveTab(1); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
getData(); | ||
}, []); | ||
|
||
return ( | ||
<div | ||
className={twMerge( | ||
'absolute right-0 top-0 flex h-full translate-x-[calc(100%-2rem)] bg-bg-secondary transition-transform', | ||
isOpen && 'translate-x-0', | ||
topOffset && 'top-11' | ||
)} | ||
> | ||
<button className="w-8" onClick={toggle}> | ||
<Arrow className={twMerge('rotate-180 transition-transform', isOpen && 'rotate-0')} /> | ||
</button> | ||
|
||
<div className="w-[400px]"> | ||
<section className="flex h-full select-none flex-col border-l-[1px] border-[#4391BF] bg-bg-secondary px-1 py-4 text-base "> | ||
<div className="flex gap-1 py-2"> | ||
<button | ||
className={twMerge( | ||
'w-1/2 border border-[#4391BF] p-2', | ||
activeTab === 0 && 'bg-[#4391BF] bg-opacity-50' | ||
)} | ||
onClick={() => setActiveTab(0)} | ||
> | ||
Содержание | ||
</button> | ||
<button | ||
className={twMerge( | ||
'w-1/2 border border-[#4391BF] p-2', | ||
activeTab === 1 && 'bg-[#4391BF] bg-opacity-50' | ||
)} | ||
onClick={() => setActiveTab(1)} | ||
> | ||
Просмотр | ||
</button> | ||
</div> | ||
|
||
{/* <input | ||
type="text" | ||
placeholder="Поиск" | ||
className="mb-2 border border-[#4391BF] px-4 py-2 outline-none" | ||
/> */} | ||
|
||
<div className="h-full overflow-y-auto scrollbar-thin scrollbar-track-slate-700 scrollbar-thumb-slate-500"> | ||
<div className={twMerge(activeTab !== 0 && 'hidden')}> | ||
{data ? ( | ||
<Tree root={data.body} borderWidth={0} onItemClicked={onItemClicked} /> | ||
) : ( | ||
<span>Загрузка</span> | ||
)} | ||
</div> | ||
|
||
<div className={twMerge('h-full', activeTab !== 1 && 'hidden')}> | ||
<Show html={html} documentLink={documentLink} /> | ||
</div> | ||
</div> | ||
</section> | ||
</div> | ||
</div> | ||
); | ||
} | ||
import { useState, useEffect } from 'react'; | ||
|
||
import { twMerge } from 'tailwind-merge'; | ||
|
||
import { ReactComponent as Arrow } from '@renderer/assets/icons/arrow.svg'; | ||
import { useDoc } from '@renderer/store/useDoc'; | ||
|
||
import Show from './components/Show'; | ||
import { Tree } from './components/Tree'; | ||
|
||
import { Settings } from '../Modules/Settings'; | ||
|
||
/*Загрузка документации*/ | ||
|
||
interface DocumentationsProps { | ||
topOffset?: boolean; | ||
} | ||
|
||
// TODO: используется для того, чтобы задать значение переменной извне, но это выглядит костыльно | ||
let SET_URL; | ||
let SET_DATA; | ||
export function setURL(url) { | ||
SET_URL(url); | ||
getData(url); | ||
} | ||
|
||
function getData(url) { | ||
fetch(url) | ||
.then((data) => data.json()) | ||
.then((data) => { | ||
SET_DATA(data); | ||
}); | ||
} | ||
|
||
export function Documentations({ topOffset = false }: DocumentationsProps) { | ||
const [url, setUrl] = useState(''); | ||
SET_URL = setUrl; | ||
const [activeTab, setActiveTab] = useState<number>(0); | ||
const [data, setData] = useState<{ body: File }>(); | ||
SET_DATA = setData; | ||
const [html, setHtml] = useState(''); | ||
const [documentLink, setDocumentLink] = useState(''); | ||
|
||
const [isOpen, toggle] = useDoc((state) => [state.isOpen, state.toggle]); | ||
|
||
const onItemClicked = (event: React.MouseEvent<HTMLLIElement, MouseEvent>, item) => { | ||
event.stopPropagation(); | ||
if (item.path.endsWith('html')) { | ||
fetch(encodeURI(`${url}${item.path}`)) | ||
.then((data) => data.text()) | ||
.then((html) => { | ||
setHtml(html); | ||
setActiveTab(1); | ||
}); | ||
} else { | ||
setHtml(''); | ||
setDocumentLink(`${url}${item.path}`); | ||
setActiveTab(1); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
Settings.getDocSettings().then((doc) => { | ||
setURL(doc.host); | ||
}); | ||
}, []); | ||
|
||
return ( | ||
<div | ||
className={twMerge( | ||
'absolute right-0 top-0 flex h-full translate-x-[calc(100%-2rem)] bg-bg-secondary transition-transform', | ||
isOpen && 'translate-x-0', | ||
topOffset && 'top-11' | ||
)} | ||
> | ||
<button className="w-8" onClick={toggle}> | ||
<Arrow className={twMerge('rotate-180 transition-transform', isOpen && 'rotate-0')} /> | ||
</button> | ||
|
||
<div className="w-[400px]"> | ||
<section className="flex h-full select-none flex-col border-l-[1px] border-[#4391BF] bg-bg-secondary px-1 py-4 text-base "> | ||
<div className="flex gap-1 py-2"> | ||
<button | ||
className={twMerge( | ||
'w-1/2 border border-[#4391BF] p-2', | ||
activeTab === 0 && 'bg-[#4391BF] bg-opacity-50' | ||
)} | ||
onClick={() => setActiveTab(0)} | ||
> | ||
Содержание | ||
</button> | ||
<button | ||
className={twMerge( | ||
'w-1/2 border border-[#4391BF] p-2', | ||
activeTab === 1 && 'bg-[#4391BF] bg-opacity-50' | ||
)} | ||
onClick={() => setActiveTab(1)} | ||
> | ||
Просмотр | ||
</button> | ||
</div> | ||
|
||
{/* <input | ||
type="text" | ||
placeholder="Поиск" | ||
className="mb-2 border border-[#4391BF] px-4 py-2 outline-none" | ||
/> */} | ||
|
||
<div className="h-full overflow-y-auto scrollbar-thin scrollbar-track-slate-700 scrollbar-thumb-slate-500"> | ||
<div className={twMerge(activeTab !== 0 && 'hidden')}> | ||
{data ? ( | ||
<Tree root={data.body} borderWidth={0} onItemClicked={onItemClicked} /> | ||
) : ( | ||
<span>Загрузка</span> | ||
)} | ||
</div> | ||
|
||
<div className={twMerge('h-full', activeTab !== 1 && 'hidden')}> | ||
<Show html={html} documentLink={documentLink} /> | ||
</div> | ||
</div> | ||
</section> | ||
</div> | ||
</div> | ||
); | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,32 @@ | ||
import { ComponentProps, forwardRef } from 'react'; | ||
|
||
import { twMerge } from 'tailwind-merge'; | ||
|
||
interface TextInputProps extends ComponentProps<'input'> { | ||
label: string; | ||
isElse: boolean; | ||
error?: boolean; | ||
errorMessage: string; | ||
} | ||
|
||
export const TextInput = forwardRef<HTMLInputElement, TextInputProps>( | ||
({ label, isElse, error, errorMessage, ...props }, ref) => { | ||
return ( | ||
<label className={twMerge('mx-1 flex flex-col', error && 'text-red-500', isElse && 'hidden')}> | ||
{label} | ||
<input | ||
className={twMerge( | ||
'w-[250px] max-w-[250px] rounded border bg-transparent px-2 py-1 outline-none transition-colors placeholder:font-normal', | ||
error && 'border-red-500 placeholder:text-red-500', | ||
!error && 'border-neutral-200 text-neutral-50 focus:border-neutral-50' | ||
)} | ||
ref={ref} | ||
{...props} | ||
maxLength={20} | ||
/> | ||
<p className="min-h-[24px] text-[14px] text-red-500">{errorMessage}</p> | ||
</label> | ||
); | ||
} | ||
); | ||
import { ComponentProps, forwardRef } from 'react'; | ||
|
||
import { twMerge } from 'tailwind-merge'; | ||
|
||
interface TextInputProps extends ComponentProps<'input'> { | ||
label: string; | ||
isHidden: boolean; | ||
error?: boolean; | ||
errorMessage: string; | ||
} | ||
|
||
export const TextInput = forwardRef<HTMLInputElement, TextInputProps>( | ||
({ label, isHidden: isElse, error, errorMessage, className, ...props }, ref) => { | ||
return ( | ||
<label className={twMerge('mx-1 flex flex-col', error && 'text-red-500', isElse && 'hidden')}> | ||
{label} | ||
<input | ||
className={twMerge( | ||
'w-[250px] max-w-[250px] rounded border bg-transparent px-2 py-1 outline-none transition-colors placeholder:font-normal', | ||
error && 'border-red-500 placeholder:text-red-500', | ||
!error && 'border-neutral-200 text-neutral-50 focus:border-neutral-50', | ||
className | ||
)} | ||
ref={ref} | ||
maxLength={20} | ||
{...props} | ||
/> | ||
<p className="min-h-[24px] text-[14px] text-red-500">{errorMessage}</p> | ||
</label> | ||
); | ||
} | ||
); |
Oops, something went wrong.