-
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.
- Loading branch information
1 parent
72a716e
commit 10e58ba
Showing
12 changed files
with
309 additions
and
47 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
import { IMovieMetaData } from './IMovieMetaData'; | ||
import { IGenericLibrary, isGenericLibrary } from './IGenericLibrary'; | ||
import { ISeriesMetaData } from './ISeriesMetaData'; | ||
import { IGenericLibrary } from './IGenericLibrary'; | ||
|
||
export type IMovieLibrary = IGenericLibrary<IMovieMetaData, 'movie'>; | ||
export type IMovieLibrary = IGenericLibrary<'movie'>; | ||
|
||
export type ISeriesLibrary = IGenericLibrary<ISeriesMetaData, 'series'>; | ||
export type ISeriesLibrary = IGenericLibrary<'series'>; | ||
|
||
export type IMusicLibrary = IGenericLibrary<any, 'music'>; | ||
export type IMusicLibrary = IGenericLibrary<'music'>; | ||
|
||
export type ILibrary = IMovieLibrary | ISeriesLibrary | IMusicLibrary; |
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Button, Typography } from '@mui/material'; | ||
import Grid from '@mui/material/Grid2'; | ||
import { ReadonlySignal, Signal, useComputed } from '@preact/signals-react'; | ||
import { useTranslation } from '@src/hooks'; | ||
import React, { ReactNode } from 'react'; | ||
|
||
interface IFormListProps<TData> { | ||
renderControl: (data: Signal<TData>) => ReactNode; | ||
values: Signal<Signal<TData>[]>; | ||
createItem: () => TData; | ||
label: ReadonlySignal<string>; | ||
} | ||
|
||
export function FormList<TData>(props: IFormListProps<TData>) { | ||
const _t = useTranslation(); | ||
|
||
return ( | ||
<Grid container spacing={1}> | ||
<Grid size={8}> | ||
<Typography>{props.label}</Typography> | ||
</Grid> | ||
<Grid size={4}> | ||
<Button | ||
fullWidth={true} | ||
onClick={() => { | ||
props.values.value = [...props.values.value, new Signal(props.createItem())]; | ||
}} | ||
> | ||
{_t('Add')} | ||
</Button> | ||
</Grid> | ||
{useComputed(() => props.values.value.map((item, index) => ( | ||
<Grid size={12}> | ||
{props.renderControl(item)} | ||
<Button onClick={() => { | ||
props.values.value = props.values.value.toSpliced(index, 1); | ||
}}>{_t('Remove')}</Button> | ||
</Grid> | ||
)))} | ||
</Grid> | ||
); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { FormControl, InputLabel, MenuItem, Select } from '@mui/material'; | ||
import { ReadonlySignal, Signal, useComputed } from '@preact/signals-react'; | ||
import React from 'react'; | ||
|
||
interface ISelectInputProps { | ||
label?: ReadonlySignal<string>; | ||
value: Signal<string>; | ||
options: { [key: string]: ReadonlySignal<string>; }; | ||
} | ||
|
||
export function SelectInput(props: ISelectInputProps) { | ||
return ( | ||
<FormControl fullWidth> | ||
<InputLabel>{props.label}</InputLabel> | ||
{useComputed(() => ( | ||
<Select | ||
label={props.label?.value} | ||
value={props.value.value} | ||
onChange={(ev) => { | ||
props.value.value = ev.target.value; | ||
}} | ||
> | ||
{Object.entries(props.options).map(([value, label]) => ( | ||
<MenuItem value={value}>{label}</MenuItem> | ||
))} | ||
</Select> | ||
))} | ||
</FormControl> | ||
); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React from 'react'; | ||
import { TextField } from '@mui/material'; | ||
import { ReadonlySignal, Signal, useComputed } from '@preact/signals-react'; | ||
|
||
interface ITextInputProps { | ||
label?: ReadonlySignal<string>; | ||
value: Signal<string>; | ||
ref?: Signal<HTMLInputElement | null>; | ||
multiline?: boolean; | ||
rows?: number; | ||
} | ||
|
||
export function TextInput(props: ITextInputProps) { | ||
return useComputed(() => ( | ||
<TextField | ||
fullWidth={true} | ||
rows={props.rows} | ||
multiline={props.multiline} | ||
label={props.label?.value} | ||
value={props.value.value} | ||
inputRef={ref => { | ||
if (props.ref) { | ||
props.ref.value = ref; | ||
} | ||
}} | ||
onChange={(ev) => { | ||
props.value.value = ev.target.value; | ||
}} | ||
/> | ||
)); | ||
} |
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,4 +1,8 @@ | ||
export { FormList } from './FormList'; | ||
export { Identicon } from './Identicon'; | ||
export { ImageView } from './ImageView'; | ||
export { Loader } from './Loader'; | ||
export { Identicon } from './Identicon'; | ||
export { SelectInput } from './SelectInput'; | ||
export { Spacer } from './Spacer'; | ||
export { TextInput } from './TextInput'; | ||
export { ThemeToggle } from './ThemeToggle'; |
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import Grid from '@mui/material/Grid2'; | ||
import { Signal, useSignal } from '@preact/signals-react'; | ||
import { useTranslation } from '@src/hooks'; | ||
import { ILibrary } from 'ipmc-interfaces'; | ||
import React, { useEffect } from 'react'; | ||
import { SelectInput, TextInput } from '../atoms'; | ||
|
||
interface ILibraryEditorProps { | ||
value: Signal<ILibrary>; | ||
} | ||
|
||
export function LibraryEditor(props: ILibraryEditorProps) { | ||
const _t = useTranslation(); | ||
|
||
const name = useSignal<string>(props.value.value.name); | ||
const type = useSignal<'movie' | 'series' | 'music'>(props.value.value.type); | ||
const upstream = useSignal<string>(props.value.value.upstream ?? ''); | ||
|
||
useEffect(() => { | ||
name.subscribe((value) => { | ||
props.value.value = { ...props.value.value, name: value }; | ||
}); | ||
type.subscribe((value) => { | ||
props.value.value = { ...props.value.value, type: value }; | ||
}); | ||
upstream.subscribe((value) => { | ||
props.value.value = { ...props.value.value, upstream: value }; | ||
}); | ||
}); | ||
|
||
return ( | ||
<Grid container spacing={2}> | ||
<Grid size={8}> | ||
<TextInput | ||
value={name} | ||
label={_t('Name')} | ||
/> | ||
</Grid> | ||
<Grid size={4}> | ||
<SelectInput | ||
value={type} | ||
label={_t('Type')} | ||
options={{ | ||
'movie': _t('Movies'), | ||
'series': _t('Series'), | ||
'music': _t('Music'), | ||
}} | ||
/> | ||
</Grid> | ||
<Grid size={12}> | ||
<TextInput | ||
value={upstream} | ||
label={_t('Upstream')} | ||
/> | ||
</Grid> | ||
</Grid> | ||
); | ||
} |
122 changes: 107 additions & 15 deletions
122
packages/ui/src/components/molecules/ProfileEditor.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
Oops, something went wrong.