mirror of
https://github.com/jkingsman/Remote-Terminal-for-MeshCore.git
synced 2026-05-15 13:56:09 +02:00
Add dropdown to choose contact addition type. Closes #216.
This commit is contained in:
+2
-2
@@ -158,10 +158,10 @@ export const api = {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ public_keys: publicKeys }),
|
||||
}),
|
||||
createContact: (publicKey: string, name?: string, tryHistorical?: boolean) =>
|
||||
createContact: (publicKey: string, name?: string, tryHistorical?: boolean, type?: number) =>
|
||||
fetchJson<Contact>('/contacts', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ public_key: publicKey, name, try_historical: tryHistorical }),
|
||||
body: JSON.stringify({ public_key: publicKey, name, type, try_historical: tryHistorical }),
|
||||
}),
|
||||
markContactRead: (publicKey: string) =>
|
||||
fetchJson<{ status: string; public_key: string }>(`/contacts/${publicKey}/mark-read`, {
|
||||
|
||||
@@ -32,7 +32,12 @@ interface NewMessageModalProps {
|
||||
nonce: number;
|
||||
} | null;
|
||||
onClose: () => void;
|
||||
onCreateContact: (name: string, publicKey: string, tryHistorical: boolean) => Promise<void>;
|
||||
onCreateContact: (
|
||||
name: string,
|
||||
publicKey: string,
|
||||
tryHistorical: boolean,
|
||||
type?: number
|
||||
) => Promise<void>;
|
||||
onCreateChannel: (name: string, key: string, tryHistorical: boolean) => Promise<void>;
|
||||
onCreateHashtagChannel: (name: string, tryHistorical: boolean) => Promise<void>;
|
||||
onBulkAddHashtagChannels: (channelNames: string[], tryHistorical: boolean) => Promise<void>;
|
||||
@@ -91,6 +96,7 @@ export function NewMessageModal({
|
||||
}: NewMessageModalProps) {
|
||||
const [tab, setTab] = useState<Tab>('new-contact');
|
||||
const [name, setName] = useState('');
|
||||
const [contactType, setContactType] = useState(1);
|
||||
const [contactKey, setContactKey] = useState('');
|
||||
const [channelKey, setChannelKey] = useState('');
|
||||
const [bulkChannelText, setBulkChannelText] = useState('');
|
||||
@@ -103,6 +109,7 @@ export function NewMessageModal({
|
||||
|
||||
const resetForm = () => {
|
||||
setName('');
|
||||
setContactType(1);
|
||||
setContactKey('');
|
||||
setChannelKey('');
|
||||
setBulkChannelText('');
|
||||
@@ -161,7 +168,7 @@ export function NewMessageModal({
|
||||
setError('Name and public key are required');
|
||||
return;
|
||||
}
|
||||
await onCreateContact(name.trim(), contactKey.trim(), tryHistorical);
|
||||
await onCreateContact(name.trim(), contactKey.trim(), tryHistorical, contactType);
|
||||
} else if (tab === 'new-channel') {
|
||||
if (!name.trim() || !channelKey.trim()) {
|
||||
setError('Channel name and key are required');
|
||||
@@ -293,6 +300,19 @@ export function NewMessageModal({
|
||||
placeholder="64-character hex public key"
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="contact-type">Type</Label>
|
||||
<select
|
||||
id="contact-type"
|
||||
value={contactType}
|
||||
onChange={(e) => setContactType(Number(e.target.value))}
|
||||
className="block h-9 w-full rounded-md border border-input bg-background px-3 text-sm shadow-sm"
|
||||
>
|
||||
<option value={1}>Client</option>
|
||||
<option value={2}>Repeater</option>
|
||||
<option value={3}>Room Server</option>
|
||||
</select>
|
||||
</div>
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value="new-channel" className="mt-4 space-y-4">
|
||||
|
||||
@@ -50,8 +50,8 @@ export function useContactsAndChannels({
|
||||
}, []);
|
||||
|
||||
const handleCreateContact = useCallback(
|
||||
async (name: string, publicKey: string, tryHistorical: boolean) => {
|
||||
const created = await api.createContact(publicKey, name || undefined, tryHistorical);
|
||||
async (name: string, publicKey: string, tryHistorical: boolean, type?: number) => {
|
||||
const created = await api.createContact(publicKey, name || undefined, tryHistorical, type);
|
||||
const data = await fetchAllContacts();
|
||||
setContacts(data);
|
||||
|
||||
|
||||
@@ -172,7 +172,7 @@ describe('NewMessageModal form reset', () => {
|
||||
await user.click(screen.getByRole('button', { name: 'Create' }));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(onCreateContact).toHaveBeenCalledWith('Bob', 'bb'.repeat(32), false);
|
||||
expect(onCreateContact).toHaveBeenCalledWith('Bob', 'bb'.repeat(32), false, 1);
|
||||
});
|
||||
expect(onClose).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user