Skip to content

Commit

Permalink
Merge pull request kruzhok-team#95 from Roundabout1/server_button_set…
Browse files Browse the repository at this point in the history
…tings

Вывести адрес компилятора и доксервера в настройки (electron-settings)
  • Loading branch information
chekoopa authored Nov 24, 2023
2 parents 1f72f06 + af0a3af commit b2c6ea5
Show file tree
Hide file tree
Showing 20 changed files with 655 additions and 434 deletions.
5 changes: 5 additions & 0 deletions src/main/electron-settings-consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ export const DEFAULT_COMPILER_SETTINGS = {
port: 8081,
};

export const DEFAULT_DOC_SETTINGS = {
host: 'https://lapki-doc.polyus-nt.ru/',
};

// названия ключей electron-settings

export const COMPILER_SETTINGS_KEY: string = 'compiler';
export const FLASHER_SETTINGS_KEY: string = 'flasher';
export const DOC_SETTINGS_KEY: string = 'doc';
export const PLATFORMS_PATH_SETTINGS_KEY: string = 'PlatformsPath';
6 changes: 6 additions & 0 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import icon from '../../resources/icon.png?asset';
import {
COMPILER_SETTINGS_KEY,
DEFAULT_COMPILER_SETTINGS,
DEFAULT_DOC_SETTINGS,
DOC_SETTINGS_KEY,
FLASHER_SETTINGS_KEY,
PLATFORMS_PATH_SETTINGS_KEY,
} from './electron-settings-consts';
Expand Down Expand Up @@ -105,6 +107,10 @@ function initSettings(): void {
port: null,
});
}

if (!settings.hasSync(DOC_SETTINGS_KEY)) {
settings.setSync(DOC_SETTINGS_KEY, DEFAULT_DOC_SETTINGS);
}
}

// Выполняется после инициализации Electron
Expand Down
3 changes: 3 additions & 0 deletions src/preload/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ declare global {
FLASHER_SETTINGS_KEY: string;
COMPILER_SETTINGS_KEY: string;
PLATFORMS_PATH_SETTINGS_KEY: string;
DEFAULT_COMPILER_SETTINGS;
DOC_SETTINGS_KEY: string;
DEFAULT_DOC_SETTINGS;
};
}
}
6 changes: 6 additions & 0 deletions src/preload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { contextBridge } from 'electron';
import { FLASHER_LOCAL_HOST, LAPKI_FLASHER } from '../main/modules/ModuleManager';
import {
COMPILER_SETTINGS_KEY,
DEFAULT_COMPILER_SETTINGS,
DEFAULT_DOC_SETTINGS,
DOC_SETTINGS_KEY,
FLASHER_SETTINGS_KEY,
PLATFORMS_PATH_SETTINGS_KEY,
} from '../main/electron-settings-consts';
Expand All @@ -12,7 +15,10 @@ const api = {
FLASHER_LOCAL_HOST,
FLASHER_SETTINGS_KEY,
COMPILER_SETTINGS_KEY,
DEFAULT_COMPILER_SETTINGS,
PLATFORMS_PATH_SETTINGS_KEY,
DOC_SETTINGS_KEY,
DEFAULT_DOC_SETTINGS,
};

// Use `contextBridge` APIs to expose Electron APIs to
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/src/components/CreateModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ export const CreateModal: React.FC<CreateModalProps> = ({
{...register('argsOneElse', {
required: 'Это поле обязательно к заполнению!',
})}
isElse={isElse}
isHidden={isElse}
error={!!errors.argsOneElse}
errorMessage={errors.argsOneElse?.message ?? ''}
/>
Expand Down Expand Up @@ -759,7 +759,7 @@ export const CreateModal: React.FC<CreateModalProps> = ({
{...register('argsTwoElse', {
required: 'Это поле обязательно к заполнению!',
})}
isElse={isElse}
isHidden={isElse}
error={!!errors.argsTwoElse}
errorMessage={errors.argsTwoElse?.message ?? ''}
/>
Expand Down
237 changes: 126 additions & 111 deletions src/renderer/src/components/Documentation/Documentation.tsx
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>
);
}
2 changes: 1 addition & 1 deletion src/renderer/src/components/MainContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export const MainContainer: React.FC<MainContainerProps> = ({
</div>
)}

<Documentations topOffset={!!isInitialized} baseUrl={'https://lapki-doc.polyus-nt.ru/'} />
<Documentations topOffset={!!isInitialized} />
</div>
);
};
63 changes: 32 additions & 31 deletions src/renderer/src/components/Modal/TextInput.tsx
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>
);
}
);
Loading

0 comments on commit b2c6ea5

Please sign in to comment.