Skip to content

Feature 13: Character State Subscriptions #138

@aphexlog

Description

@aphexlog

Description

Subscribe to character updates in real-time so changes from other sources (AI, backend) reflect immediately.

Priority

P2 (Medium) - Real-time collaboration support

Estimated Effort

2 days

Dependencies

Acceptance Criteria

  • GraphQL subscription for character updates
  • UI updates when character modified externally
  • Subscription cleanup on unmount
  • Works across multiple tabs/devices
  • Handles subscription errors gracefully

Implementation Details

useEffect(() => {
  
  const subscription = dataClient.models.GameMasterCharacter.observeQuery({
    filter: { id: { eq: characterState.id } }
  }).subscribe({
    next: ({ items }) => {
      if (items[0]) {
        setCharacterState(items[0]);
        console.log('Character updated via subscription');
      }
    },
    error: (error) => {
      console.error('Subscription error:', error);
    }
  });
  
  return () => subscription.unsubscribe();
}, [characterState?.id]);

Testing

  • Update in one tab → reflects in other
  • Backend update → UI updates
  • Subscription cleans up properly
  • Error handling works

Related Documentation

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2: MediumMedium priority - enhanced UXcharacter-sheetCharacter sheet featuresenhancementNew feature or requestgame-masterGame Master mode features

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions