Skip to content

Commit

Permalink
feat(front): let it also be inferred when selecting a path from a button
Browse files Browse the repository at this point in the history
  • Loading branch information
SARDONYX-sard committed Nov 9, 2024
1 parent c3fc423 commit b5adee3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function ConvertButton({ loading, progress, ...props }: Props) {
return (
<LoadingButton
disabled={loading || isComplete}
endIcon={loading || isComplete ? <CircularProgressWithLabel value={progress} /> : <ConvertIcon />}
endIcon={loading || isComplete ? undefined : <ConvertIcon />}
loading={loading}
loadingPosition='end'
sx={{
Expand Down Expand Up @@ -74,7 +74,13 @@ export function ConvertButton({ loading, progress, ...props }: Props) {
variant='contained'
{...props}
>
<span>{loading ? t('converting-btn') : isComplete ? 'OK' : t('convert-btn')}</span>
<span>
{loading
? `${t('converting-btn')} ${<CircularProgressWithLabel value={progress} />}`
: isComplete
? `OK ${<CircularProgressWithLabel value={progress} />}`
: t('convert-btn')}
</span>
</LoadingButton>
);
}
13 changes: 10 additions & 3 deletions gui/frontend/src/components/organisms/ConvertForm/ConvertForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ import { FormProvider, type SubmitHandler, useForm } from 'react-hook-form';

import { useTranslation } from '@/components/hooks/useTranslation';
import { ConvertNav, ConvertNavPadding } from '@/components/organisms/ConvertNav';
import { parseDarPath } from '@/lib/path/parseDarPath';
import { STORAGE } from '@/lib/storage';
import { PRIVATE_CACHE_OBJ, PUB_CACHE_OBJ } from '@/lib/storage/cacheKeys';
import { convertDar2oar } from '@/services/api/convert';
import { progressListener } from '@/services/api/event';
import { LOG, type LogLevel } from '@/services/api/log';

import { parseDarPath } from '../../../lib/path/parseDarPath';

import { CheckboxField } from './CheckboxField';
import { InputModInfoField } from './InputModInfoField';
import { InputPathField } from './InputPathField';
Expand Down Expand Up @@ -120,6 +119,7 @@ export function ConvertForm() {

{pathFields.map((props) => {
let onChange: ComponentPropsWithRef<typeof InputPathField>['onChange'] | undefined;
let setPathHook: ((path: string) => void) | undefined;

if (props.name === 'src') {
onChange = (e) => {
Expand All @@ -129,8 +129,15 @@ export function ConvertForm() {
setValue('modName', parsedPath.modName ?? '');
}
};
setPathHook = (path: string) => {
if (getValues('inferPath')) {
const parsedPath = parseDarPath(path);
setValue('dst', parsedPath.oarRoot);
setValue('modName', parsedPath.modName ?? '');
}
};
}
return <InputPathField key={props.name} onChange={onChange} {...props} />;
return <InputPathField key={props.name} onChange={onChange} setPathHook={setPathHook} {...props} />;
})}

<Grid columnSpacing={1} container={true} gap={2} sx={{ width: '100%' }}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,17 @@ type Props = {
placeholder: string;
helperText: string | ReactNode;
onChange?: TextFieldProps['onChange'];
setPathHook?: (path: string) => void;
};

export const InputPathField = ({ name, label, placeholder, helperText, onChange: onChangeOuter }: Props) => {
export const InputPathField = ({
name,
label,
placeholder,
helperText,
onChange: onChangeOuter,
setPathHook,
}: Props) => {
const { control, getValues, setValue } = useFormContext<FormProps>();

const path = (() => {
Expand All @@ -33,6 +41,7 @@ export const InputPathField = ({ name, label, placeholder, helperText, onChange:
const handleSetPath = (path: string) => {
setValue(name, path);
setPathToStorage(name, path);
setPathHook?.(path);
};

return (
Expand Down

0 comments on commit b5adee3

Please sign in to comment.