mirror of
https://github.com/DocNR/POWR.git
synced 2025-04-22 16:51:33 +00:00

Implements database tables and services for workout and template storage: - Updates schema to version 5 with new workout and template tables - Adds WorkoutService for CRUD operations on workouts - Enhances TemplateService for template management - Creates NostrWorkoutService for bidirectional Nostr event handling - Implements React hooks for database access - Connects workout store to database layer for persistence - Improves offline support with publication queue This change ensures workouts and templates are properly saved to SQLite and can be referenced across app sessions, while maintaining Nostr integration for social sharing.
65 lines
1.9 KiB
TypeScript
65 lines
1.9 KiB
TypeScript
// utils/converter.ts - Simplified to just forward to NostrWorkoutService
|
|
|
|
import { Workout } from '@/types/workout';
|
|
import { WorkoutTemplate } from '@/types/templates';
|
|
import { NostrEvent } from '@/types/nostr';
|
|
import { NostrWorkoutService } from '@/lib/db/services/NostrWorkoutService';
|
|
|
|
/**
|
|
* Helper function to find a tag value in a Nostr event
|
|
* @deprecated Use NostrWorkoutService.findTagValue instead
|
|
*/
|
|
export function findTagValue(tags: string[][], name: string): string | null {
|
|
return NostrWorkoutService.findTagValue(tags, name);
|
|
}
|
|
|
|
/**
|
|
* Get all values for a specific tag name
|
|
* @deprecated Use NostrWorkoutService.getTagValues instead
|
|
*/
|
|
export function getTagValues(tags: string[][], name: string): string[] {
|
|
return NostrWorkoutService.getTagValues(tags, name);
|
|
}
|
|
|
|
/**
|
|
* Get template tag information
|
|
* @deprecated Use NostrWorkoutService.getTemplateTag instead
|
|
*/
|
|
export function getTagValueByName(tags: string[][], name: string): string | null {
|
|
return NostrWorkoutService.findTagValue(tags, name);
|
|
}
|
|
|
|
/**
|
|
* Get tag values matching a pattern
|
|
*/
|
|
export function getTemplateTag(tags: string[][]): { reference: string, relay: string } | undefined {
|
|
return NostrWorkoutService.getTemplateTag(tags);
|
|
}
|
|
|
|
/**
|
|
* Convert a workout to a Nostr event
|
|
*/
|
|
export function workoutToNostrEvent(workout: Workout, isLimited: boolean = false): NostrEvent {
|
|
return NostrWorkoutService.workoutToNostrEvent(workout, isLimited);
|
|
}
|
|
|
|
/**
|
|
* Convert a Nostr event to a workout
|
|
*/
|
|
export function nostrEventToWorkout(event: NostrEvent): Workout {
|
|
return NostrWorkoutService.nostrEventToWorkout(event);
|
|
}
|
|
|
|
/**
|
|
* Convert a template to a Nostr event
|
|
*/
|
|
export function templateToNostrEvent(template: WorkoutTemplate): NostrEvent {
|
|
return NostrWorkoutService.templateToNostrEvent(template);
|
|
}
|
|
|
|
/**
|
|
* Convert a Nostr event to a template
|
|
*/
|
|
export function nostrEventToTemplate(event: NostrEvent): WorkoutTemplate {
|
|
return NostrWorkoutService.nostrEventToTemplate(event);
|
|
} |