Select a profile by clicking anywhere on its card
This commit is contained in:
parent
2e4005d24d
commit
653945a5e8
3 changed files with 44 additions and 0 deletions
|
|
@ -132,6 +132,14 @@ export function ProfilesScreen({ onCreateProfile }: ProfilesScreenProps) {
|
||||||
<article
|
<article
|
||||||
key={profile.npub}
|
key={profile.npub}
|
||||||
className={`profile-card${profile.is_active ? ' is-active' : ''}`}
|
className={`profile-card${profile.is_active ? ' is-active' : ''}`}
|
||||||
|
onClick={
|
||||||
|
profile.is_active
|
||||||
|
? undefined
|
||||||
|
: (event) => {
|
||||||
|
if ((event.target as HTMLElement).closest('button, a, input')) return;
|
||||||
|
void onSelect(profile.npub);
|
||||||
|
}
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<div className="profile-card-top">
|
<div className="profile-card-top">
|
||||||
<Avatar
|
<Avatar
|
||||||
|
|
|
||||||
|
|
@ -1048,6 +1048,14 @@ select {
|
||||||
border-color: var(--success);
|
border-color: var(--success);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.profile-card:not(.is-active) {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.profile-card:not(.is-active):hover {
|
||||||
|
border-color: var(--primary);
|
||||||
|
}
|
||||||
|
|
||||||
.profile-card-top {
|
.profile-card-top {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,34 @@ describe('ProfilesScreen', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('selects a profile when its card is clicked', async () => {
|
||||||
|
const backend = createFakeBackend();
|
||||||
|
installFakeBackend(backend);
|
||||||
|
const user = userEvent.setup();
|
||||||
|
renderWithApp(<ProfilesScreen onCreateProfile={vi.fn()} />);
|
||||||
|
|
||||||
|
await screen.findByText('Bob');
|
||||||
|
await user.click(screen.getByText('Bob'));
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(backend.state.active_profile?.npub).toBe(BOB);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not select a profile when an action button inside the card is clicked', async () => {
|
||||||
|
const backend = createFakeBackend();
|
||||||
|
installFakeBackend(backend);
|
||||||
|
const user = userEvent.setup();
|
||||||
|
renderWithApp(<ProfilesScreen onCreateProfile={vi.fn()} />);
|
||||||
|
|
||||||
|
await screen.findByText('Bob');
|
||||||
|
const copyButtons = screen.getAllByRole('button', { name: 'Copy public key' });
|
||||||
|
await user.click(copyButtons[copyButtons.length - 1]);
|
||||||
|
|
||||||
|
expect(backend.copied).toContain(BOB);
|
||||||
|
expect(backend.state.active_profile?.npub).toBe(ALICE);
|
||||||
|
});
|
||||||
|
|
||||||
it('disables Select for the active profile and copies public keys', async () => {
|
it('disables Select for the active profile and copies public keys', async () => {
|
||||||
const backend = createFakeBackend();
|
const backend = createFakeBackend();
|
||||||
installFakeBackend(backend);
|
installFakeBackend(backend);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue