@@ -1,25 +1,31 @@
11import { GroupUpdateInitial, MetadataUpdateInitial } from "@urbit/api";
2−import { useQuery, useQueryClient } from "react-query"
2+import { useQuery } from "react-query"
33import api from "../api"
4−import { PostOption } from "../types/sphinx";
4+import { PostOption, PostType, Search } from "../types/sphinx";
55
66
77
88export const useGroups = (): PostOption[] => {
99 const { data } = useQuery('metadata', () => api.subscribeOnce<{ 'metadata-update': MetadataUpdateInitial }>('metadata-store', '/all'));
1010 const { data: groupData } = useQuery('groups', () => api.subscribeOnce<{ groupUpdate: GroupUpdateInitial }>('group-store', '/groups'));
11+ const { data: d } = useQuery('group-listings', () => api.scry<Search>({
12+ app: 'sphinx',
13+ path: '/lookup/group/0/999'
14+ }));
1115
12− //web+urbitgraph://group/~nocsyx-lassul/celestial-systems
13− console.log(data, groupData)
16+ if (!data || !groupData || !d) {
17+ return [];
18+ }
1419
15− return data && groupData ? Object.entries(data['metadata-update'].associations)
20+ return Object.entries(data['metadata-update'].associations)
1621 .filter(([k,v]) => v['app-name'] === 'groups' && 'open' in (groupData.groupUpdate.initial[v.resource]?.policy || {}))
1722 .map(([k,v]) => ({ key: k, post: {
18− type: 'group',
23+ type: 'group' as PostType,
1924 title: v.metadata.title,
2025 link: v.group.replace('/ship/', 'web+urbitgraph://group/'),
2126 image: v.metadata.picture,
2227 description: v.metadata.description,
2328 tags: ['group']
24− }})) : [];
29+ }}))
30+ .filter(({ post }) => !d.listings.some(l => l.post.link === post.link || l.post.title === post.title));
2531}