forked from jsnbuchanan/crowd-funder-for-time-pwa
Refactor: eliminate "special" entity type and use DID-based logic
Replace string-based entity type matching with DID-based logic for "You" and "Unnamed" entities. Treat these as regular person entities instead of special types. - Remove "special" type from EntitySelectionEvent interface - Update EntityGrid to emit "You" and "Unnamed" as person entities - Simplify SpecialEntityCard emit structure (remove entityType parameter) - Refactor GiftedDialog to process all person entities with DID-based logic - Update ContactGiftingView and HomeView to use DID-based entity creation - Remove string literals "You" and "Unnamed" from method signatures
This commit is contained in:
@@ -310,16 +310,13 @@ export default class EntityGrid extends Vue {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle special entity selection from SpecialEntityCard
|
* Handle special entity selection from SpecialEntityCard
|
||||||
|
* Treat "You" and "Unnamed" as person entities
|
||||||
*/
|
*/
|
||||||
handleEntitySelected(event: {
|
handleEntitySelected(event: { data: { did?: string; name: string } }): void {
|
||||||
type: string;
|
// Convert special entities to person entities since they represent people
|
||||||
entityType: string;
|
|
||||||
data: { did?: string; name: string };
|
|
||||||
}): void {
|
|
||||||
this.emitEntitySelected({
|
this.emitEntitySelected({
|
||||||
type: "special",
|
type: "person",
|
||||||
entityType: event.entityType,
|
data: event.data as Contact,
|
||||||
data: event.data,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -327,13 +324,11 @@ export default class EntityGrid extends Vue {
|
|||||||
|
|
||||||
@Emit("entity-selected")
|
@Emit("entity-selected")
|
||||||
emitEntitySelected(data: {
|
emitEntitySelected(data: {
|
||||||
type: "person" | "project" | "special";
|
type: "person" | "project";
|
||||||
entityType?: string;
|
data: Contact | PlanData;
|
||||||
data: Contact | PlanData | { did?: string; name: string };
|
|
||||||
}): {
|
}): {
|
||||||
type: "person" | "project" | "special";
|
type: "person" | "project";
|
||||||
entityType?: string;
|
data: Contact | PlanData;
|
||||||
data: Contact | PlanData | { did?: string; name: string };
|
|
||||||
} {
|
} {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,9 +56,8 @@ interface EntityData {
|
|||||||
* Entity selection event data structure
|
* Entity selection event data structure
|
||||||
*/
|
*/
|
||||||
interface EntitySelectionEvent {
|
interface EntitySelectionEvent {
|
||||||
type: "person" | "project" | "special";
|
type: "person" | "project";
|
||||||
entityType?: string;
|
data: Contact | PlanData;
|
||||||
data: Contact | PlanData | EntityData;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -561,20 +561,21 @@ export default class GiftedDialog extends Vue {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle entity selection from EntitySelectionStep
|
* Handle entity selection from EntitySelectionStep
|
||||||
* @param entity - The selected entity (person, project, or special) with stepType
|
* @param entity - The selected entity (person or project) with stepType
|
||||||
*/
|
*/
|
||||||
handleEntitySelected(entity: {
|
handleEntitySelected(entity: {
|
||||||
type: "person" | "project" | "special";
|
type: "person" | "project";
|
||||||
entityType?: string;
|
data: Contact | PlanData;
|
||||||
data: Contact | PlanData | { did?: string; name: string };
|
|
||||||
stepType: string;
|
stepType: string;
|
||||||
}) {
|
}) {
|
||||||
if (entity.type === "person") {
|
if (entity.type === "person") {
|
||||||
const contact = entity.data as Contact;
|
const contact = entity.data as Contact;
|
||||||
|
// Apply DID-based logic for person entities
|
||||||
|
const processedContact = this.processPersonEntity(contact);
|
||||||
if (entity.stepType === "giver") {
|
if (entity.stepType === "giver") {
|
||||||
this.selectGiver(contact);
|
this.selectGiver(processedContact);
|
||||||
} else {
|
} else {
|
||||||
this.selectRecipient(contact);
|
this.selectRecipient(processedContact);
|
||||||
}
|
}
|
||||||
} else if (entity.type === "project") {
|
} else if (entity.type === "project") {
|
||||||
const project = entity.data as PlanData;
|
const project = entity.data as PlanData;
|
||||||
@@ -583,33 +584,22 @@ export default class GiftedDialog extends Vue {
|
|||||||
} else {
|
} else {
|
||||||
this.selectRecipientProject(project);
|
this.selectRecipientProject(project);
|
||||||
}
|
}
|
||||||
} else if (entity.type === "special") {
|
}
|
||||||
// Handle special entities like "You" and "Unnamed"
|
}
|
||||||
if (entity.entityType === "you") {
|
|
||||||
// "You" entity selected
|
/**
|
||||||
const youEntity = {
|
* Processes person entities using DID-based logic for "You" and "Unnamed"
|
||||||
did: this.activeDid,
|
*/
|
||||||
name: "You",
|
private processPersonEntity(contact: Contact): Contact {
|
||||||
};
|
if (contact.did === this.activeDid) {
|
||||||
if (entity.stepType === "giver") {
|
// If DID matches active DID, create "You" entity
|
||||||
this.giver = youEntity;
|
return { ...contact, name: "You" };
|
||||||
|
} else if (!contact.did || contact.did === "") {
|
||||||
|
// If DID is empty/null, create "Unnamed" entity
|
||||||
|
return { ...contact, name: "Unnamed" };
|
||||||
} else {
|
} else {
|
||||||
this.receiver = youEntity;
|
// Return the contact as-is
|
||||||
}
|
return contact;
|
||||||
this.firstStep = false;
|
|
||||||
} else if (entity.entityType === "unnamed") {
|
|
||||||
// "Unnamed" entity selected
|
|
||||||
const unnamedEntity = {
|
|
||||||
did: "",
|
|
||||||
name: "Unnamed",
|
|
||||||
};
|
|
||||||
if (entity.stepType === "giver") {
|
|
||||||
this.giver = unnamedEntity;
|
|
||||||
} else {
|
|
||||||
this.receiver = unnamedEntity;
|
|
||||||
}
|
|
||||||
this.firstStep = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -124,8 +124,6 @@ export default class SpecialEntityCard extends Vue {
|
|||||||
handleClick(): void {
|
handleClick(): void {
|
||||||
if (this.selectable && !this.conflicted) {
|
if (this.selectable && !this.conflicted) {
|
||||||
this.emitEntitySelected({
|
this.emitEntitySelected({
|
||||||
type: "special",
|
|
||||||
entityType: this.entityType,
|
|
||||||
data: this.entityData,
|
data: this.entityData,
|
||||||
});
|
});
|
||||||
} else if (this.conflicted && this.notify) {
|
} else if (this.conflicted && this.notify) {
|
||||||
@@ -145,13 +143,7 @@ export default class SpecialEntityCard extends Vue {
|
|||||||
// Emit methods using @Emit decorator
|
// Emit methods using @Emit decorator
|
||||||
|
|
||||||
@Emit("entity-selected")
|
@Emit("entity-selected")
|
||||||
emitEntitySelected(data: {
|
emitEntitySelected(data: { data: { did?: string; name: string } }): {
|
||||||
type: string;
|
|
||||||
entityType: string;
|
|
||||||
data: { did?: string; name: string };
|
|
||||||
}): {
|
|
||||||
type: string;
|
|
||||||
entityType: string;
|
|
||||||
data: { did?: string; name: string };
|
data: { did?: string; name: string };
|
||||||
} {
|
} {
|
||||||
return data;
|
return data;
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class="block w-full text-center text-sm uppercase bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-3 py-1.5 rounded-md"
|
class="block w-full text-center text-sm uppercase bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-3 py-1.5 rounded-md"
|
||||||
@click="openDialog('You')"
|
@click="openDialog({ did: activeDid, name: 'You' })"
|
||||||
>
|
>
|
||||||
<font-awesome icon="gift" class="fa-fw"></font-awesome>
|
<font-awesome icon="gift" class="fa-fw"></font-awesome>
|
||||||
</button>
|
</button>
|
||||||
@@ -48,7 +48,7 @@
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class="block w-full text-center text-sm uppercase bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-3 py-1.5 rounded-md"
|
class="block w-full text-center text-sm uppercase bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-3 py-1.5 rounded-md"
|
||||||
@click="openDialog('Unnamed')"
|
@click="openDialog({ did: '', name: 'Unnamed' })"
|
||||||
>
|
>
|
||||||
<font-awesome icon="gift" class="fa-fw"></font-awesome>
|
<font-awesome icon="gift" class="fa-fw"></font-awesome>
|
||||||
</button>
|
</button>
|
||||||
@@ -207,7 +207,7 @@ export default class ContactGiftingView extends Vue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
openDialog(contact?: GiverReceiverInputInfo | "Unnamed" | "You") {
|
openDialog(contact?: GiverReceiverInputInfo) {
|
||||||
// Determine the selected entity based on contact type
|
// Determine the selected entity based on contact type
|
||||||
const selectedEntity = this.createEntityFromContact(contact);
|
const selectedEntity = this.createEntityFromContact(contact);
|
||||||
|
|
||||||
@@ -231,19 +231,26 @@ export default class ContactGiftingView extends Vue {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an entity object from the contact parameter
|
* Creates an entity object from the contact parameter
|
||||||
|
* Uses DID-based logic to determine "You" and "Unnamed" entities
|
||||||
*/
|
*/
|
||||||
private createEntityFromContact(
|
private createEntityFromContact(
|
||||||
contact?: GiverReceiverInputInfo | "Unnamed" | "You",
|
contact?: GiverReceiverInputInfo,
|
||||||
): GiverReceiverInputInfo | undefined {
|
): GiverReceiverInputInfo | undefined {
|
||||||
if (contact === "You") {
|
if (!contact) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle GiverReceiverInputInfo object
|
||||||
|
if (contact.did === this.activeDid) {
|
||||||
|
// If DID matches active DID, create "You" entity
|
||||||
return { did: this.activeDid, name: "You" };
|
return { did: this.activeDid, name: "You" };
|
||||||
} else if (contact === "Unnamed") {
|
} else if (!contact.did || contact.did === "") {
|
||||||
|
// If DID is empty/null, create "Unnamed" entity
|
||||||
return { did: "", name: "Unnamed" };
|
return { did: "", name: "Unnamed" };
|
||||||
} else if (contact) {
|
} else {
|
||||||
// Create a copy of the contact to avoid modifying the original
|
// Create a copy of the contact to avoid modifying the original
|
||||||
return { ...contact };
|
return { ...contact };
|
||||||
}
|
}
|
||||||
return undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1475,30 +1475,41 @@ export default class HomeView extends Vue {
|
|||||||
* @param giver Optional contact info for giver
|
* @param giver Optional contact info for giver
|
||||||
* @param description Optional gift description
|
* @param description Optional gift description
|
||||||
*/
|
*/
|
||||||
openDialog(giver?: GiverReceiverInputInfo | "Unnamed", prompt?: string) {
|
openDialog(giver?: GiverReceiverInputInfo, prompt?: string) {
|
||||||
if (giver === "Unnamed") {
|
// Determine the giver entity based on DID logic
|
||||||
// Special case: Pass undefined to trigger Step 1, but with "Unnamed" pre-selected
|
const giverEntity = this.createGiverEntity(giver);
|
||||||
|
|
||||||
(this.$refs.giftedDialog as GiftedDialog).open(
|
(this.$refs.giftedDialog as GiftedDialog).open(
|
||||||
undefined,
|
giverEntity,
|
||||||
{
|
{
|
||||||
did: this.activeDid,
|
did: this.activeDid,
|
||||||
name: "You",
|
name: "You", // In HomeView, we always use "You" as the giver
|
||||||
} as GiverReceiverInputInfo,
|
} as GiverReceiverInputInfo,
|
||||||
undefined,
|
undefined,
|
||||||
prompt,
|
prompt,
|
||||||
);
|
);
|
||||||
// Immediately select "Unnamed" and move to Step 2
|
}
|
||||||
(this.$refs.giftedDialog as GiftedDialog).selectGiver();
|
|
||||||
|
/**
|
||||||
|
* Creates giver entity using DID-based logic
|
||||||
|
*/
|
||||||
|
private createGiverEntity(
|
||||||
|
giver?: GiverReceiverInputInfo,
|
||||||
|
): GiverReceiverInputInfo | undefined {
|
||||||
|
if (!giver) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle GiverReceiverInputInfo object
|
||||||
|
if (giver.did === this.activeDid) {
|
||||||
|
// If DID matches active DID, create "You" entity
|
||||||
|
return { did: this.activeDid, name: "You" };
|
||||||
|
} else if (!giver.did || giver.did === "") {
|
||||||
|
// If DID is empty/null, create "Unnamed" entity
|
||||||
|
return { did: "", name: "Unnamed" };
|
||||||
} else {
|
} else {
|
||||||
(this.$refs.giftedDialog as GiftedDialog).open(
|
// Return the giver as-is
|
||||||
giver,
|
return giver;
|
||||||
{
|
|
||||||
did: this.activeDid,
|
|
||||||
name: "You",
|
|
||||||
} as GiverReceiverInputInfo,
|
|
||||||
undefined,
|
|
||||||
prompt,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1627,10 +1638,7 @@ export default class HomeView extends Vue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
openPersonDialog(
|
openPersonDialog(giver?: GiverReceiverInputInfo, prompt?: string) {
|
||||||
giver?: GiverReceiverInputInfo | "Unnamed",
|
|
||||||
prompt?: string,
|
|
||||||
) {
|
|
||||||
this.showProjectsDialog = false;
|
this.showProjectsDialog = false;
|
||||||
this.openDialog(giver, prompt);
|
this.openDialog(giver, prompt);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user