Files
eranos/src/contexts/AppContext.ts
T
shakespeare.diy a3d24927d4 Add three-mode stats calculation: NIP-85 Only, Manual Only, and Both
Replace the binary nip85OnlyMode boolean with a statsMode enum that supports three options:
- "nip85-only": Show only pre-computed NIP-85 stats (fastest, may be empty)
- "manual-only": Always calculate stats from relay queries (slower, guaranteed)
- "both": Use NIP-85 when available with manual fallback (recommended default)

Updated components:
- AppContext: Changed nip85OnlyMode to statsMode with StatsMode type
- AppProvider: Updated Zod schema to validate three-mode enum
- useTrending.ts: Implemented logic for all three modes in useEventStats and useBatchEventStats
- AdvancedSettings: Replaced switch with radio group for better UX

Default remains "nip85-only" for optimal performance.

Co-authored-by: shakespeare.diy <assistant@shakespeare.diy>
2026-02-19 04:50:07 -06:00

68 lines
2.4 KiB
TypeScript

import { createContext } from "react";
export type Theme = "dark" | "light" | "black" | "pink";
export interface RelayMetadata {
/** List of relays with read/write permissions */
relays: { url: string; read: boolean; write: boolean }[];
/** Unix timestamp of when the relay list was last updated */
updatedAt: number;
}
/** Which "Other Stuff" content types to show in the sidebar nav and include in feeds. */
export interface FeedSettings {
/** Show Vines (kind 34236) link in sidebar */
showVines: boolean;
/** Show Polls (kind 1068) link in sidebar */
showPolls: boolean;
/** Show Treasures link in sidebar */
showTreasures: boolean;
/** Show Geocache listings (kind 37516) in Treasures */
showTreasureGeocaches: boolean;
/** Show Found logs (kind 7516) in Treasures */
showTreasureFoundLogs: boolean;
/** Show Colors (kind 3367) link in sidebar */
showColors: boolean;
/** Show Follow Packs (kind 39089) link in sidebar */
showPacks: boolean;
/** Include Vines in the follows/global feed */
feedIncludeVines: boolean;
/** Include Polls in the follows/global feed */
feedIncludePolls: boolean;
/** Include Treasure geocaches in the follows/global feed */
feedIncludeTreasureGeocaches: boolean;
/** Include Treasure found logs in the follows/global feed */
feedIncludeTreasureFoundLogs: boolean;
/** Include Colors in the follows/global feed */
feedIncludeColors: boolean;
/** Include Follow Packs in the follows/global feed */
feedIncludePacks: boolean;
}
/** Stats calculation mode: NIP-85 only, manual only, or both */
export type StatsMode = "nip85-only" | "manual-only" | "both";
export interface AppConfig {
/** Current theme */
theme: Theme;
/** NIP-65 relay list metadata */
relayMetadata: RelayMetadata;
/** Whether to use app default relays in addition to user relays */
useAppRelays: boolean;
/** Feed and sidebar content settings */
feedSettings: FeedSettings;
/** NIP-85 stats pubkey source (hex format) */
nip85StatsPubkey: string;
/** Stats calculation mode: NIP-85 only, manual only, or both */
statsMode: StatsMode;
}
export interface AppContextType {
/** Current application configuration */
config: AppConfig;
/** Update configuration using a callback that receives current config and returns new config */
updateConfig: (updater: (currentConfig: Partial<AppConfig>) => Partial<AppConfig>) => void;
}
export const AppContext = createContext<AppContextType | undefined>(undefined);