-
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
e88a96e
commit ce72c23
Showing
11 changed files
with
138 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React from 'react'; | ||
import { useComputed, useSignal } from "@preact/signals-react"; | ||
import { Button, Card, CardActions, CardContent, CardHeader, TextField } from "@mui/material"; | ||
import { IConfigurationService } from '../../service'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
export function ProfileEditor(props: { id: string, configService: IConfigurationService, onCancel: () => void, onSave: () => void }) { | ||
const { configService, id, onCancel, onSave } = props; | ||
const [_t] = useTranslation(); | ||
|
||
const profile = useComputed(() => { | ||
return configService.getProfile(id); | ||
}); | ||
|
||
const name = useSignal<string>(profile.value?.name ?? id); | ||
|
||
function save() { | ||
configService.setProfile(id, { | ||
...(profile.value ?? {}), | ||
name: name.value, | ||
}); | ||
onSave(); | ||
} | ||
|
||
return ( | ||
<Card> | ||
<CardHeader title={_t('EditProfile')} /> | ||
<CardContent> | ||
<TextField | ||
label={_t('Name')} | ||
value={name} | ||
onChange={(ev) => { | ||
name.value = ev.target.value; | ||
}} | ||
/> | ||
</CardContent> | ||
<CardActions> | ||
<Button onClick={() => onCancel()}>{_t('Cancel')}</Button> | ||
<Button onClick={() => save()}>{_t('Save')}</Button> | ||
</CardActions> | ||
</Card> | ||
); | ||
} |
75 changes: 51 additions & 24 deletions
75
packages/core/src/components/molecules/ProfileSelector.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,51 +1,78 @@ | ||
import { Button, ButtonGroup, Card, CardActions, CardHeader, Dialog, Stack } from "@mui/material"; | ||
import { useComputed, useSignal } from "@preact/signals-react"; | ||
import React from "react"; | ||
import { IConfigurationService, IProfile } from "../../service"; | ||
import { CardActions, Button, ButtonGroup, Card, CardContent, Stack, Dialog, DialogTitle, DialogContent, DialogActions } from "@mui/material"; | ||
import { useTranslation } from "react-i18next"; | ||
import { useComputed, useSignal } from "@preact/signals-react"; | ||
import { IConfigurationService, IProfile } from "../../service"; | ||
import { uuid } from '../../util'; | ||
import { ProfileEditor } from "./ProfileEditor"; | ||
|
||
export function ProfileSelector(props: { profile?: IProfile, profiles: string[], switchProfile: (name: string) => void, configService: IConfigurationService }) { | ||
export function ProfileSelector(props: { profile?: IProfile, switchProfile: (name: string) => void, configService: IConfigurationService; }) { | ||
const { configService } = props; | ||
|
||
const [_t] = useTranslation(); | ||
const editing = useSignal<string | undefined>(undefined); | ||
const profiles = useSignal<(IProfile & { id: string; })[]>(loadProfiles()); | ||
|
||
function loadProfiles() { | ||
return configService.getProfiles().map(p => ({ | ||
...configService.getProfile(p), | ||
id: p, | ||
})); | ||
} | ||
|
||
const dialog = useComputed(() => { | ||
if (editing.value !== undefined) { | ||
if (editing.value == undefined) { | ||
return <></>; | ||
} | ||
return ( | ||
<Dialog | ||
open={true} | ||
onClose={() => editing.value = undefined} | ||
> | ||
<DialogTitle>{_t('EditProfile')}</DialogTitle> | ||
<DialogContent> | ||
TODO | ||
</DialogContent> | ||
<DialogActions> | ||
<Button onClick={() => editing.value = undefined}>{_t('Cancel')}</Button> | ||
<Button>{_t('Save')}</Button> | ||
</DialogActions> | ||
<ProfileEditor | ||
id={editing.value} | ||
configService={configService} | ||
onCancel={() => editing.value = undefined} | ||
onSave={() => { | ||
editing.value = undefined; | ||
profiles.value = loadProfiles(); | ||
}} | ||
/> | ||
</Dialog> | ||
); | ||
}); | ||
|
||
const content = useComputed(() => profiles.value.map(p => ( | ||
<Card key={p.id}> | ||
<CardHeader title={p.name} subheader={p.id} /> | ||
<CardActions> | ||
<ButtonGroup> | ||
<Button | ||
color={"error"} | ||
onClick={() => { | ||
configService.removeProfile(p.id); | ||
profiles.value = loadProfiles(); | ||
}} | ||
>{_t('Delete')}</Button> | ||
<Button | ||
onClick={() => editing.value = p.id} | ||
>{_t('Edit')}</Button> | ||
<Button | ||
variant={'contained'} | ||
onClick={() => props.switchProfile(p.id)} | ||
>{_t('Start')}</Button> | ||
</ButtonGroup> | ||
</CardActions> | ||
</Card> | ||
))); | ||
|
||
return (<> | ||
<Stack spacing={1}> | ||
{props.profiles.map(p => <Card key={p}> | ||
<CardContent>{p}</CardContent> | ||
<CardActions> | ||
<ButtonGroup> | ||
<Button onClick={() => editing.value = p}>{_t('Edit')}</Button> | ||
<Button onClick={() => props.switchProfile(p)}>{_t('Start')}</Button> | ||
</ButtonGroup> | ||
</CardActions> | ||
</Card>)} | ||
{content} | ||
<div> | ||
<Button onClick={() => editing.value = ''}>{_t('AddProfile')}</Button> | ||
<Button onClick={() => editing.value = uuid()}>{_t('AddProfile')}</Button> | ||
</div> | ||
</Stack> | ||
{dialog} | ||
</>); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -10,3 +10,4 @@ export type { | |
IInternalProfile, | ||
IRemoteProfile, | ||
} from './service'; | ||
export { uuid } from './util'; |
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,16 +1,18 @@ | ||
{ | ||
"AddProfile": "Profil hinzufügen", | ||
"Cancel": "Abbrechen", | ||
"Delete": "Löschen", | ||
"Edit": "Bearbeiten", | ||
"EditProfile": "Profil bearbeiten", | ||
"Home": "Home", | ||
"Loading": "Laden...", | ||
"Logout": "Abmelden", | ||
"Movies": "Filme", | ||
"Name": "Name", | ||
"Save": "Speichern", | ||
"Search": "Suche", | ||
"Start": "Starten", | ||
"Starting": "Starten...", | ||
"Stopping": "Stoppen...", | ||
"SwarmKey": "Schwarm Schlüssel" | ||
} | ||
} |
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,16 +1,18 @@ | ||
{ | ||
"AddProfile": "Add profile", | ||
"Cancel": "Cancel", | ||
"Delete": "Delete", | ||
"Edit": "Edit", | ||
"EditProfile": "Edit profile", | ||
"Home": "Home", | ||
"Loading": "Loading...", | ||
"Logout": "Logout", | ||
"Movies": "Movies", | ||
"Name": "Name", | ||
"Save": "Save", | ||
"Search": "Search", | ||
"Start": "Start", | ||
"Starting": "Starting node...", | ||
"Stopping": "Stopping node...", | ||
"SwarmKey": "Swarm Key" | ||
} | ||
} |
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,5 @@ | ||
export function uuid() { | ||
return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, c => | ||
(+c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> +c / 4).toString(16) | ||
); | ||
} |
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