Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements contact deletion functionality #420

Merged
merged 37 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
6bfce8c
feat(ui): add deleteContact method to RelayClient for contact removal
MasterK0927 Jan 8, 2025
fc3094b
feat(ui): add deleteContact method to ContactStore for contact removal
MasterK0927 Jan 8, 2025
4922638
feat(ui): add ButtonDelete component for contact removal in ContactLi…
MasterK0927 Jan 8, 2025
3ef85ba
fix(ui): handle errors during contact deletion in ContactListItem and…
MasterK0927 Jan 8, 2025
4f74f64
fix(ui): display error toast on contact deletion failure in ContactLi…
MasterK0927 Jan 9, 2025
42c181c
fix(ui): update delete icon stroke color to currentColor in svgIcons
MasterK0927 Jan 9, 2025
6d9566e
fix(i18n): add error message for contact deletion failure in translat…
MasterK0927 Jan 9, 2025
4cccbd1
Merge develop into feat/remove-contact
MasterK0927 Jan 9, 2025
0a2714c
fix(i18n): update delete contact error message to use common translat…
MasterK0927 Jan 9, 2025
0a2e604
fix(contact): remove error throw for non-existent contact in deleteCo…
MasterK0927 Jan 9, 2025
57e81da
fix(ui): simplify ButtonDelete click handling by using stopPropagatio…
MasterK0927 Jan 9, 2025
00bca13
Merge branch 'develop' into feat/remove-contact
MasterK0927 Jan 10, 2025
7d265bf
fix(ui): set default value for moreClasses in ButtonDelete component
MasterK0927 Jan 10, 2025
6dd7fc6
Merge branch 'develop' into feat/remove-contact
MasterK0927 Jan 10, 2025
c7933a8
refactor(ui): remove ButtonDelete component and replace with ButtonIc…
MasterK0927 Jan 10, 2025
9129f7e
Merge branch 'develop' into feat/remove-contact
MasterK0927 Jan 10, 2025
51a5331
refactor(ui): update translation keys for unconfirmed and view action…
MasterK0927 Jan 12, 2025
4d142a0
refactor(svgIcons): update guidelines for adding SVG properties based…
MasterK0927 Jan 12, 2025
d9ea8e4
fix(RelayClient): correct formatting of payload argument in create_co…
MasterK0927 Jan 12, 2025
94074af
feat(Dialog): add a reusable dialog component with confirm and cancel…
MasterK0927 Jan 12, 2025
c9a1123
feat(Contacts): implement delete contact functionality with confirmat…
MasterK0927 Jan 12, 2025
e66e1bd
refactor(ContactListItem): remove unused delete functionality and rel…
MasterK0927 Jan 12, 2025
512cfbe
feat(Contacts): update delete contact success message and dialog text…
MasterK0927 Jan 12, 2025
485729d
Merge branch 'develop' into feat/remove-contact
MasterK0927 Jan 12, 2025
00db411
feat(Dialog): localize dialog text and button labels for delete conta…
MasterK0927 Jan 12, 2025
bf146c0
fix(ContactListItem): update condition to display unconfirmed status …
MasterK0927 Jan 13, 2025
c405862
Merge branch 'develop' into feat/remove-contact
MasterK0927 Jan 14, 2025
7734daa
fix(svgIcons): update stroke icon properties to include width and height
MasterK0927 Jan 14, 2025
8735f9d
fix(contacts): simplify conversation and profiles initialization logic
MasterK0927 Jan 14, 2025
f8c1299
fix(translations): remove redundant delete contact title from English…
MasterK0927 Jan 14, 2025
fc488ae
fix(dialog): makes it responsive for smaller viewports and event disp…
MasterK0927 Jan 14, 2025
b192a8c
fix(contactStore): streamline contact deletion logic by updating loca…
MasterK0927 Jan 14, 2025
299ec1d
fix(contacts): remove loading state and simplify profile loading logic
MasterK0927 Jan 14, 2025
2644c47
refactor(ui): wait for action to complete before closing dialog, expi…
mattyg Jan 16, 2025
6fc07fa
chore(ui): grammer
mattyg Jan 16, 2025
ecdfa9b
doc: changelog
mattyg Jan 16, 2025
857abb9
Merge branch 'develop' into feat/remove-contact
mattyg Jan 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions ui/src/lib/ButtonDelete.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<script lang="ts">
import SvgIcon from "./SvgIcon.svelte";
export let moreClasses: string;
MasterK0927 marked this conversation as resolved.
Show resolved Hide resolved
</script>

<button
type="button"
on:click|stopPropagation
class="inline-flex h-8 w-8 items-center justify-center rounded-full transition-opacity hover:opacity-75 focus:outline-none"
aria-label="Delete"
>
<SvgIcon icon="delete" {moreClasses} />
</button>
MasterK0927 marked this conversation as resolved.
Show resolved Hide resolved
56 changes: 36 additions & 20 deletions ui/src/lib/ContactListItem.svelte
MasterK0927 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import type { AgentPubKeyB64 } from "@holochain/client";
import Avatar from "$lib/Avatar.svelte";
import { getContext, onMount } from "svelte";
import ButtonDelete from "$lib/ButtonDelete.svelte";
import toast from "svelte-french-toast";

const contactStore = getContext<{ getStore: () => ContactStore }>("contactStore").getStore();

Expand All @@ -18,32 +20,46 @@
onMount(async () => {
hasAgentJoinedDht = await contactStore.getHasAgentJoinedDht(agentPubKeyB64);
});

async function handleDelete(event: MouseEvent) {
try {
await contact.delete();
} catch (err) {
console.error(err);
MasterK0927 marked this conversation as resolved.
Show resolved Hide resolved
toast.error($t("common.delete_contact_error"));
}
}
</script>

<button
class="-ml-1 mb-2 flex w-full items-center justify-between rounded-3xl py-1 pl-1 pr-2 {selected &&
'bg-tertiary-500 dark:bg-secondary-500'}"
on:click
>
<Avatar size={38} agentPubKeyB64={$contact.publicKeyB64} moreClasses="mr-3" />
<p
class="dark:text-tertiary-100 flex-1 text-start font-bold {hasAgentJoinedDht
? 'text-secondary-400 dark:!text-secondary-300'
: ''}"
>
{$contact.fullName}
{#if hasAgentJoinedDht}
<span class="text-secondary-400 ml-1 text-xs">{$t("common.unconfirmed")}</span>
{/if}
</p>
{#if selected}
<ButtonInline
on:click={() => goto("/contacts/" + $contact.publicKeyB64)}
moreClasses="dark:bg-secondary-700 "
<div class="flex flex-1 items-center">
<Avatar size={38} agentPubKeyB64={$contact.publicKeyB64} moreClasses="mr-3" />
<p
class="dark:text-tertiary-100 flex-1 text-start font-bold {hasAgentJoinedDht
? 'text-secondary-400 dark:!text-secondary-300'
: ''}"
>
{$t("common.view")}
</ButtonInline>
{:else}
<span class="text-primary-500 text-lg font-extrabold">+</span>
{/if}
{$contact.fullName}
{#if hasAgentJoinedDht}
<span class="text-secondary-400 ml-1 text-xs">{$t("create.unconfirmed")}</span>
MasterK0927 marked this conversation as resolved.
Show resolved Hide resolved
{/if}
</p>
</div>
<div class="flex items-center space-x-2">
{#if selected}
<ButtonInline
on:click={() => goto("/contacts/" + $contact.publicKeyB64)}
moreClasses="dark:bg-secondary-700 "
>
{$t("create.view")}
MasterK0927 marked this conversation as resolved.
Show resolved Hide resolved
</ButtonInline>
{:else}
<span class="text-primary-500 text-lg font-extrabold">+</span>
<ButtonDelete moreClasses="h-5 w-5" on:click={handleDelete} />
{/if}
</div>
</button>
1 change: 1 addition & 0 deletions ui/src/lib/svgIcons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,5 @@ export const svgIcons: { [key: string]: string } = {
pdf: '<svg width="100%" height="100%" fill="currentColor" xmlns="http://www.w3.org/2000/svg" viewBox="2 2 20 20"><path d="M3.9985 2C3.44749 2 3 2.44405 3 2.9918V21.0082C3 21.5447 3.44476 22 3.9934 22H20.0066C20.5551 22 21 21.5489 21 20.9925L20.9997 7L16 2H3.9985ZM10.5 7.5H12.5C12.5 9.98994 14.6436 12.6604 17.3162 13.5513L16.8586 15.49C13.7234 15.0421 10.4821 16.3804 7.5547 18.3321L6.3753 16.7191C7.46149 15.8502 8.50293 14.3757 9.27499 12.6534C10.0443 10.9373 10.5 9.07749 10.5 7.5ZM11.1 13.4716C11.3673 12.8752 11.6043 12.2563 11.8037 11.6285C12.2754 12.3531 12.8553 13.0182 13.5102 13.5953C12.5284 13.7711 11.5666 14.0596 10.6353 14.4276C10.8 14.1143 10.9551 13.7948 11.1 13.4716Z"></path></svg>',
fileClip:
'<svg width="100%" height="100%" fill="currentColor" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 492.308 492.308" xml:space="preserve"><path d="M398.918 91.764v228.087c0 84.236-68.529 152.764-152.764 152.764S93.389 404.087 93.389 319.851V114.495c0-52.274 42.529-94.803 94.808-94.803 52.274 0 94.798 42.529 94.798 94.803l-.019 192.803c0 20.995-17.077 38.072-38.067 38.072-20.995 0-38.072-17.077-38.072-38.072V133.135h-19.692v174.163c0 31.851 25.913 57.764 57.764 57.764s57.76-25.914 57.76-57.764l.019-192.803C302.688 51.361 251.327 0 188.197 0c-63.135 0-114.5 51.361-114.5 114.495v205.356c0 95.091 77.365 172.457 172.457 172.457s172.457-77.365 172.457-172.457V91.764z"/></svg>',
delete: '<svg width="100%" height="100%" viewBox="0 0 25 25" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M5 6.66671H20.8333M19.1667 7.50004V19.1667C19.1667 19.8297 18.9033 20.4656 18.4344 20.9345C17.9656 21.4033 17.3297 21.6667 16.6667 21.6667H9.16667C8.50363 21.6667 7.86774 21.4033 7.3989 20.9345C6.93006 20.4656 6.66667 19.8297 6.66667 19.1667V7.50004M10.8333 6.66671V4.16671C10.8333 3.94569 10.9211 3.73373 11.0774 3.57745C11.2337 3.42117 11.4457 3.33337 11.6667 3.33337H14.1667C14.3877 3.33337 14.5996 3.42117 14.7559 3.57745C14.9122 3.73373 15 3.94569 15 4.16671V6.66671M10.8333 10.8334V16.6667M15 10.8334V16.6667" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>',
MasterK0927 marked this conversation as resolved.
Show resolved Hide resolved
};
18 changes: 18 additions & 0 deletions ui/src/store/ContactStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface ContactStore {
initialize: () => Promise<void>;
create: (val: Contact, cellIdB64: CellIdB64) => Promise<void>;
update: (val: Contact) => Promise<void>;
delete: (agentPubKeyB64: AgentPubKeyB64) => Promise<void>;
getHasAgentJoinedDht: (agentPubKeyB64: AgentPubKeyB64) => Promise<boolean>;
getAsProfileExtended: (agentPubKeyB64: AgentPubKeyB64) => ProfileExtended;
subscribe: (
Expand Down Expand Up @@ -80,6 +81,21 @@ export function createContactStore(client: RelayClient): ContactStore {
);
}

/**
* Delete a contact
*/
async function deleteContact(agentPubKeyB64: AgentPubKeyB64) {
const contact = contacts.getKeyValue(agentPubKeyB64);
await client.deleteContact(contact.originalActionHash);
// Updates the local stores
contacts.removeKeyValue(agentPubKeyB64);
cellIds.update((d) => {
MasterK0927 marked this conversation as resolved.
Show resolved Hide resolved
const updated = { ...d };
delete updated[agentPubKeyB64];
return updated;
});
}

/**
* Fetch contacts data and load into writable
*/
Expand Down Expand Up @@ -195,6 +211,7 @@ export function createContactStore(client: RelayClient): ContactStore {

create,
update,
delete: deleteContact,

getHasAgentJoinedDht,
getAsProfileExtended,
Expand All @@ -218,6 +235,7 @@ export function deriveOneContactStore(contactStore: ContactStore, agentPubKeyB64

return {
update: contactStore.update,
delete: () => contactStore.delete(agentPubKeyB64),
getHasAgentJoinedDht,
getAsProfileExtended,
subscribe,
Expand Down
11 changes: 10 additions & 1 deletion ui/src/store/RelayClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ export class RelayClient {
cell_id: this.provisionedRelayCellId,
zome_name: ZOME_NAME,
fn_name: "create_contact",
payload,
payload,
MasterK0927 marked this conversation as resolved.
Show resolved Hide resolved
});
}

Expand All @@ -332,4 +332,13 @@ export class RelayClient {
payload,
});
}

public async deleteContact(originalContactHash: ActionHash): Promise<ActionHash> {
return this.client.callZome({
cell_id: this.provisionedRelayCellId,
zome_name: ZOME_NAME,
fn_name: "delete_contact",
payload: originalContactHash,
});
}
}
3 changes: 2 additions & 1 deletion ui/src/translations/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"create_group": "Create group",
"create_new_contact": "Create New Contact",
"created": "Created: {{date:date;}}",
"delete_contact_error": "Error deleting contact",
"download": "Download",
"download_file_error": "Failed to download file",
"download_file_success": "File downloaded successfully",
Expand Down Expand Up @@ -90,4 +91,4 @@
"welcome_text_2": "Private, encrypted and secured by keys only you control.",
"what_is_your_name": "What is your name?",
"you": "You"
}
}