From 86552306c25dd94527b439be146083d0e405572f Mon Sep 17 00:00:00 2001 From: Liam Fitzgerald Date: Fri, 16 Apr 2021 15:59:02 +1000 Subject: [PATCH] interface: add getters for stores --- pkg/interface/src/logic/state/group.ts | 2 +- pkg/interface/src/logic/state/metadata.ts | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/pkg/interface/src/logic/state/group.ts b/pkg/interface/src/logic/state/group.ts index 4fe3999f69..c8f5eef2a0 100644 --- a/pkg/interface/src/logic/state/group.ts +++ b/pkg/interface/src/logic/state/group.ts @@ -16,7 +16,7 @@ const useGroupState = createState('Group', { }, ['groups']); export function useGroup(group: string) { - return useGroupState(useCallback(s => s.groups[group], [group])); + return useGroupState(useCallback(s => s.groups[group] as Group | undefined, [group])); } export function useGroupForAssoc(association: Association) { diff --git a/pkg/interface/src/logic/state/metadata.ts b/pkg/interface/src/logic/state/metadata.ts index fabffca86e..f09e824eed 100644 --- a/pkg/interface/src/logic/state/metadata.ts +++ b/pkg/interface/src/logic/state/metadata.ts @@ -1,4 +1,5 @@ -import { MetadataUpdatePreview, Associations } from "@urbit/api"; +import { useCallback } from 'react'; +import { MetadataUpdatePreview, Association, Associations } from "@urbit/api"; import { BaseState, createState } from "./base"; @@ -9,6 +10,14 @@ export interface MetadataState extends BaseState { // preview: (group: string) => Promise; }; +export function useAssocForGraph(graph: string) { + return useMetadataState(useCallback(s => s.associations.graph[graph] as Association | undefined, [graph])); +} + +export function useAssocForGroup(group: string) { + return useMetadataState(useCallback(s => s.associations.groups[group] as Association | undefined, [group])); +} + const useMetadataState = createState('Metadata', { associations: { groups: {}, graph: {}, contacts: {}, chat: {}, link: {}, publish: {} }, // preview: async (group): Promise => { @@ -54,4 +63,4 @@ const useMetadataState = createState('Metadata', { }); -export default useMetadataState; \ No newline at end of file +export default useMetadataState;