Refactor: simplify GiftedDialog with explicit entity type props

Replace complex updateEntityTypes() method with explicit giverEntityType and
recipientEntityType props. This makes the component more declarative and
maintainable by removing hidden logic and making entity type relationships
clear at the call site.

- Remove updateEntityTypes() method and related watchers
- Add explicit giverEntityType and recipientEntityType props with defaults
- Update all views to use inline logic for entity type determination
- Fix entity type preservation in navigation flows
- Enhance query parameter passing for better context preservation
- Fix recipient reset issue in ContactGiftingView
- Resolve entity type mismatch in HomeView project button flow

Files changed:
- GiftedDialog.vue: Remove complex logic, add explicit props
- EntitySelectionStep.vue: Enhanced query parameter handling
- ContactGiftingView.vue: Improved context preservation
- HomeView.vue, ProjectViewView.vue, ClaimView.vue, ContactsView.vue:
  Updated to use explicit entity type props
- Add refactoring documentation
This commit is contained in:
Jose Olarte III
2025-08-03 11:49:46 +08:00
parent 371cf763c8
commit 06f3a4c7c2
8 changed files with 288 additions and 106 deletions

View File

@@ -67,9 +67,10 @@
<GiftedDialog
ref="giftedDialog"
:giver-entity-type="giverEntityType"
:recipient-entity-type="recipientEntityType"
:from-project-id="fromProjectId"
:to-project-id="toProjectId"
:show-projects="showProjects"
:is-from-project-view="isFromProjectView"
/>
</section>
@@ -213,7 +214,7 @@ export default class ContactGiftingView extends Vue {
// Preserve the existing giver from the context
if (this.giverEntityType === "project") {
giver = {
// no did, because it's a project
did: this.giverProjectHandleId,
name: this.giverProjectName,
image: this.giverProjectImage,
handleId: this.giverProjectHandleId,
@@ -253,7 +254,7 @@ export default class ContactGiftingView extends Vue {
// We're selecting a giver, so the contact becomes the giver
giver = contact as GiverReceiverInputInfo; // Safe because we know contact is not "Unnamed" or undefined
// Recipient is either a project or the current user
// Preserve the existing recipient from the context
if (this.recipientEntityType === "project") {
recipient = {
did: this.recipientProjectHandleId,
@@ -262,7 +263,20 @@ export default class ContactGiftingView extends Vue {
handleId: this.recipientProjectHandleId,
};
} else {
recipient = { did: this.activeDid, name: "You" };
// Check if the preserved recipient was "Unnamed" (empty DID) or a regular contact
if (this.recipientDid === "") {
// Recipient was "Unnamed"
recipient = { did: "", name: "Unnamed" };
} else if (this.recipientDid) {
// Recipient was a regular contact
recipient = {
did: this.recipientDid,
name: this.recipientProjectName || "Someone",
};
} else {
// Fallback to current user
recipient = { did: this.activeDid, name: "You" };
}
}
} else {
// We're selecting a recipient, so the contact becomes the recipient
@@ -276,13 +290,21 @@ export default class ContactGiftingView extends Vue {
image: this.giverProjectImage,
handleId: this.giverProjectHandleId,
};
} else if (this.giverDid) {
giver = {
did: this.giverDid,
name: this.giverProjectName || "Someone",
};
} else {
giver = { did: this.activeDid, name: "You" };
// Check if the preserved giver was "Unnamed" (empty DID) or a regular contact
if (this.giverDid === "") {
// Giver was "Unnamed"
giver = { did: "", name: "Unnamed" };
} else if (this.giverDid) {
// Giver was a regular contact
giver = {
did: this.giverDid,
name: this.giverProjectName || "Someone",
};
} else {
// Fallback to current user
giver = { did: this.activeDid, name: "You" };
}
}
}