diff --git a/frontend/src/api/relationships.ts b/frontend/src/api/relationships.ts index 4f90dff..34ac673 100644 --- a/frontend/src/api/relationships.ts +++ b/frontend/src/api/relationships.ts @@ -6,12 +6,18 @@ const port = window.location.port; const API_URL = protocol + '//' + hostname + (port ? ':' + port : '') + '/api'; +export type RELATIONSHIP_TYPES = 'freund' | 'partner' | 'familie' | 'arbeitskolleg' | 'custom'; + +export const RELATIONSHIP_LABELS = { + freund: 'Friend', partner: 'Partner', familie: 'Family', arbeitskolleg: 'Colleague', custom: 'Custom', +}; + // Types export interface Relationship { _id: string; source: string; target: string; - type: 'freund' | 'partner' | 'familie' | 'arbeitskolleg' | 'custom'; + type: RELATIONSHIP_TYPES; customType?: string; network: string; createdAt: string; @@ -21,12 +27,12 @@ export interface Relationship { export interface CreateRelationshipData { source: string; target: string; - type: 'freund' | 'partner' | 'familie' | 'arbeitskolleg' | 'custom'; + type: RELATIONSHIP_TYPES; customType?: string; } export interface UpdateRelationshipData { - type?: 'freund' | 'partner' | 'familie' | 'arbeitskolleg' | 'custom'; + type?: RELATIONSHIP_TYPES; customType?: string; } diff --git a/frontend/src/components/FriendshipNetwork.tsx b/frontend/src/components/FriendshipNetwork.tsx index 943cce6..e67b05f 100644 --- a/frontend/src/components/FriendshipNetwork.tsx +++ b/frontend/src/components/FriendshipNetwork.tsx @@ -37,9 +37,7 @@ import { // Import visible canvas graph component import CanvasGraph from './CanvasGraph'; - -// Define types -type RelationshipType = 'freund' | 'partner' | 'familie' | 'arbeitskolleg' | 'custom'; +import { RELATIONSHIP_LABELS, RELATIONSHIP_TYPES } from '../api/relationships'; interface PersonNode { _id: string; @@ -65,9 +63,7 @@ const RELATIONSHIP_COLORS = { custom: '#9CA3AF', // Gray }; -const RELATIONSHIP_LABELS = { - freund: 'Friend', partner: 'Partner', familie: 'Family', arbeitskolleg: 'Colleague', custom: 'Custom', -}; + // Main FriendshipNetwork component const FriendshipNetwork: React.FC = () => { @@ -130,7 +126,7 @@ const FriendshipNetwork: React.FC = () => { const [editPerson, setEditPerson] = useState(null); const [newRelationship, setNewRelationship] = useState({ - source: '', target: '', type: 'freund' as RelationshipType, customType: '', notes: '', bidirectional: true, + source: '', target: '', type: 'freund' as RELATIONSHIP_TYPES, customType: '', notes: '', bidirectional: true, }); // Filter states @@ -776,7 +772,7 @@ const FriendshipNetwork: React.FC = () => { style={{ backgroundColor: color }} > - {RELATIONSHIP_LABELS[type as RelationshipType]} + {RELATIONSHIP_LABELS[type as RELATIONSHIP_TYPES]} ))} @@ -913,14 +909,14 @@ const FriendshipNetwork: React.FC = () => { {Object.entries(RELATIONSHIP_COLORS).map(([type, color]) => ())} @@ -1268,7 +1264,7 @@ const FriendshipNetwork: React.FC = () => { focus:outline-none focus:ring-2 focus:ring-indigo-500 text-white" value={newRelationship.type} onChange={e => setNewRelationship({ - ...newRelationship, type: e.target.value as RelationshipType, + ...newRelationship, type: e.target.value as RELATIONSHIP_TYPES, })} > {Object.entries(RELATIONSHIP_LABELS).map(([value, label]) => (