mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-18 21:01:23 +02:00
New shared package enabling bidirectional links between records across apps (e.g. todo→calendar, task→file). Each link creates a forward+reverse pair sharing a pairId for efficient queries from both sides. Stored in dedicated IndexedDB (manacore-links), synced via mana-sync. Includes: types, store, mutations, reactive queries, cached display data resolvers, ManaLinkBadge and ManaLinkList UI components. Integrates into Todo app as first consumer — link store initialized in layout, ManaLinkList rendered in TaskEditModal. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
34 lines
976 B
TypeScript
34 lines
976 B
TypeScript
/**
|
|
* ManaLink — Display Data Resolvers
|
|
*
|
|
* Helpers to build cached display data from app metadata.
|
|
*/
|
|
|
|
import { getManaApp } from '@manacore/shared-branding';
|
|
import type { AppIconId } from '@manacore/shared-branding';
|
|
import type { LinkCachedData } from './types.js';
|
|
|
|
/**
|
|
* Build LinkCachedData from app branding + a title.
|
|
* Called by the app creating the link to populate offline-friendly display data.
|
|
*/
|
|
export function buildCachedData(appId: string, title: string, subtitle?: string): LinkCachedData {
|
|
const app = getManaApp(appId as AppIconId);
|
|
return {
|
|
title,
|
|
subtitle,
|
|
icon: app?.icon,
|
|
color: app?.color,
|
|
appName: app?.name,
|
|
fetchedAt: new Date().toISOString(),
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Check if cached data is stale (older than threshold).
|
|
* Default: 24 hours.
|
|
*/
|
|
export function isCacheStale(cached: LinkCachedData, maxAgeMs = 24 * 60 * 60 * 1000): boolean {
|
|
const age = Date.now() - new Date(cached.fetchedAt).getTime();
|
|
return age > maxAgeMs;
|
|
}
|