-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #184 from tloncorp/t/gear
gear: migrate from deprecated packages + use gear
- Loading branch information
Showing
67 changed files
with
11,196 additions
and
6,238 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { Flag } from './hark'; | ||
import { Flag } from "@/gear"; | ||
|
||
export interface Contact { | ||
nickname: string; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './types'; | ||
export * from './lib'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import { useCallback, useMemo } from 'react'; | ||
import _ from 'lodash'; | ||
import api from '@/api'; | ||
import { BaseState, createState } from '@/state/base'; | ||
import { | ||
ContactAnon, | ||
ContactEdit, | ||
ContactEditField, | ||
ContactHeed, | ||
ContactNews, | ||
ContactRolodex, | ||
} from '@/gear'; | ||
import { Patp } from '@urbit/http-api'; | ||
import { preSig } from '@urbit/aura'; | ||
import produce from 'immer'; | ||
|
||
export interface BaseContactState { | ||
contacts: ContactRolodex; | ||
nackedContacts: Set<Patp>; | ||
edit: (fields: ContactEditField[]) => Promise<void>; | ||
/** removes our profile */ | ||
anon: () => Promise<void>; | ||
/** subscribes to profile updates */ | ||
heed: (ships: string[]) => Promise<void>; | ||
fetchAll: () => Promise<void>; | ||
start: () => void; | ||
[ref: string]: unknown; | ||
} | ||
|
||
type ContactState = BaseContactState & BaseState<BaseContactState>; | ||
|
||
function contactAction<T>(data: T) { | ||
return { | ||
app: 'contacts', | ||
mark: 'contact-action', | ||
json: data, | ||
}; | ||
} | ||
|
||
const useContactState = createState<BaseContactState>( | ||
'Contact', | ||
(set, get) => ({ | ||
contacts: {}, | ||
nackedContacts: new Set(), | ||
fetchAll: async () => { | ||
const contacts = await api.scry<ContactRolodex>({ | ||
app: 'contacts', | ||
path: '/all', | ||
}); | ||
|
||
set( | ||
produce((draft: BaseContactState) => { | ||
draft.contacts = { | ||
...draft.contacts, | ||
...contacts, | ||
}; | ||
}) | ||
); | ||
}, | ||
edit: async (contactFields) => { | ||
await api.poke<ContactEdit>(contactAction({ edit: contactFields })); | ||
}, | ||
anon: async () => { | ||
await api.poke<ContactAnon>(contactAction({ anon: null })); | ||
}, | ||
heed: async (ships) => { | ||
await api.poke<ContactHeed>(contactAction({ heed: ships })); | ||
}, | ||
start: () => { | ||
get().fetchAll(); | ||
|
||
api.subscribe({ | ||
app: 'contacts', | ||
path: '/news', | ||
event: (event: ContactNews) => { | ||
set( | ||
produce((draft: ContactState) => { | ||
if (event.con) { | ||
draft.contacts[event.who] = event.con; | ||
} else { | ||
delete draft.contacts[event.who]; | ||
} | ||
}) | ||
); | ||
}, | ||
}); | ||
}, | ||
}), | ||
{ | ||
partialize: ({ contacts }) => ({ contacts }), | ||
}, | ||
[] | ||
); | ||
|
||
export const emptyContact = { | ||
nickname: '', | ||
bio: '', | ||
status: '', | ||
color: '0x0', | ||
avatar: null, | ||
cover: null, | ||
groups: [] as string[], | ||
}; | ||
|
||
const selContacts = (s: ContactState) => s.contacts; | ||
export function useContacts() { | ||
return useContactState(selContacts); | ||
} | ||
|
||
export function useMemoizedContacts() { | ||
return useMemo(() => useContactState.getState().contacts, []); | ||
} | ||
|
||
export function useContact(ship: string) { | ||
return useContactState( | ||
useCallback((s) => s.contacts[preSig(ship)] || emptyContact, [ship]) | ||
); | ||
} | ||
|
||
export function useOurContact() { | ||
return useContact(window.our); | ||
} | ||
|
||
export default useContactState; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Flag } from "@/gear"; | ||
|
||
export interface Contact { | ||
nickname: string; | ||
bio: string; | ||
status: string; | ||
color: string; | ||
avatar: string | null; | ||
cover: string | null; | ||
groups: string[]; | ||
} | ||
|
||
export interface ContactAddGroup { | ||
'add-group': Flag; | ||
} | ||
|
||
export interface ContactDelGroup { | ||
'del-group': Flag; | ||
} | ||
|
||
export type ContactEditField = | ||
| Pick<Contact, 'nickname'> | ||
| Pick<Contact, 'bio'> | ||
| Pick<Contact, 'status'> | ||
| Pick<Contact, 'color'> | ||
| Pick<Contact, 'avatar'> | ||
| Pick<Contact, 'cover'> | ||
| ContactAddGroup | ||
| ContactDelGroup; | ||
|
||
export type ContactsAction = ContactAnon | ContactEdit | ContactHeed; | ||
|
||
export interface ContactAnon { | ||
anon: null; | ||
} | ||
|
||
export interface ContactEdit { | ||
edit: ContactEditField[]; | ||
} | ||
|
||
export interface ContactHeed { | ||
heed: string[]; | ||
} | ||
|
||
export type ContactRolodex = Record<string, Contact | null>; | ||
|
||
export interface ContactNews { | ||
who: string; | ||
con: Contact | null; | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './lib'; | ||
export * from './types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { Poke, Scry } from '@urbit/http-api'; | ||
import { Chad } from './types'; | ||
|
||
export function chadIsRunning(chad: Chad) { | ||
return 'glob' in chad || 'site' in chad; | ||
} | ||
|
||
export const scryCharges: Scry = { | ||
app: 'docket', | ||
path: '/charges' | ||
}; | ||
|
||
export const scryDockets: Scry = { | ||
app: 'docket', | ||
path: '/dockets' | ||
}; | ||
|
||
export const scryTreaties: Scry = { | ||
app: 'treaty', | ||
path: '/treaties' | ||
}; | ||
|
||
export const scryDefaultAlly: Scry = { | ||
app: 'treaty', | ||
path: '/default-ally' | ||
}; | ||
|
||
export const scryAllies: Scry = { | ||
app: 'treaty', | ||
path: '/allies' | ||
}; | ||
|
||
export const scryAllyTreaties = (ship: string): Scry => ({ | ||
app: 'treaty', | ||
path: `/treaties/${ship}` | ||
}); | ||
|
||
/** | ||
* Uninstall a desk, and remove docket | ||
*/ | ||
export function docketUninstall(desk: string): Poke<string> { | ||
return { | ||
app: 'docket', | ||
mark: 'docket-uninstall', | ||
json: desk | ||
}; | ||
} | ||
|
||
export function docketInstall(ship: string, desk: string): Poke<any> { | ||
return { | ||
app: 'docket', | ||
mark: 'docket-install', | ||
json: `${ship}/${desk}` | ||
}; | ||
} | ||
|
||
export function allyShip(ship: string): Poke<any> { | ||
return { | ||
app: 'treaty', | ||
mark: 'ally-update-0', | ||
json: { | ||
add: ship | ||
} | ||
}; | ||
} |
Oops, something went wrong.