mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-11-10 10:05:09 +03:00
parent
cfb10b621c
commit
43e15be781
25
pkg/grid/package-lock.json
generated
25
pkg/grid/package-lock.json
generated
@ -1166,6 +1166,11 @@
|
||||
"integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==",
|
||||
"dev": true
|
||||
},
|
||||
"bn.js": {
|
||||
"version": "4.12.0",
|
||||
"resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.12.0.tgz",
|
||||
"integrity": "sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA=="
|
||||
},
|
||||
"brace-expansion": {
|
||||
"version": "1.1.11",
|
||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
|
||||
@ -3601,12 +3606,22 @@
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
|
||||
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
|
||||
},
|
||||
"lodash.chunk": {
|
||||
"version": "4.2.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.chunk/-/lodash.chunk-4.2.0.tgz",
|
||||
"integrity": "sha1-ZuXOH3btJ7QwPYxlEujRIW6BBrw="
|
||||
},
|
||||
"lodash.clonedeep": {
|
||||
"version": "4.5.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz",
|
||||
"integrity": "sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8=",
|
||||
"dev": true
|
||||
},
|
||||
"lodash.isequal": {
|
||||
"version": "4.5.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz",
|
||||
"integrity": "sha1-QVxEePK8wwEgwizhDtMib30+GOA="
|
||||
},
|
||||
"lodash.merge": {
|
||||
"version": "4.6.2",
|
||||
"resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz",
|
||||
@ -5285,6 +5300,16 @@
|
||||
"isobject": "^3.0.0"
|
||||
}
|
||||
},
|
||||
"urbit-ob": {
|
||||
"version": "5.0.1",
|
||||
"resolved": "https://registry.npmjs.org/urbit-ob/-/urbit-ob-5.0.1.tgz",
|
||||
"integrity": "sha512-qGNAwu87XNkW3g8ah4fUwmh2EKXtsdhEbyEiE5qX4Op17rhLH3HSkvu8g9z+MhqX51Uz9sf8ktvqJj/IRwETIQ==",
|
||||
"requires": {
|
||||
"bn.js": "^4.11.8",
|
||||
"lodash.chunk": "^4.2.0",
|
||||
"lodash.isequal": "^4.5.0"
|
||||
}
|
||||
},
|
||||
"uri-js": {
|
||||
"version": "4.4.1",
|
||||
"resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz",
|
||||
|
@ -39,6 +39,7 @@
|
||||
"react-error-boundary": "^3.1.3",
|
||||
"react-router-dom": "^5.2.0",
|
||||
"slugify": "^1.6.0",
|
||||
"urbit-ob": "^5.0.1",
|
||||
"zustand": "^3.5.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@ -3,7 +3,7 @@ import { RouteComponentProps } from 'react-router-dom';
|
||||
import fuzzy from 'fuzzy';
|
||||
import { Treaty } from '@urbit/api';
|
||||
import { ShipName } from '../../components/ShipName';
|
||||
import useDocketState, { useAllyTreaties } from '../../state/docket';
|
||||
import useDocketState, { useAllyTreaties, useAllies } from '../../state/docket';
|
||||
import { useLeapStore } from '../Nav';
|
||||
import { AppList } from '../../components/AppList';
|
||||
import { addRecentDev } from './Home';
|
||||
@ -18,6 +18,19 @@ export const Apps = ({ match }: AppsProps) => {
|
||||
}));
|
||||
const provider = match?.params.ship;
|
||||
const treaties = useAllyTreaties(provider);
|
||||
const allies = useAllies();
|
||||
const isAllied = provider in allies;
|
||||
|
||||
useEffect(() => {
|
||||
if (Object.keys(allies).length > 0 && !isAllied) {
|
||||
useDocketState
|
||||
.getState()
|
||||
.addAlly(provider)
|
||||
.then(() => {
|
||||
return useDocketState.getState().fetchAllyTreaties(provider);
|
||||
});
|
||||
}
|
||||
}, [allies, isAllied, provider]);
|
||||
const results = useMemo(() => {
|
||||
if (!treaties) {
|
||||
return undefined;
|
||||
|
@ -1,7 +1,8 @@
|
||||
import React, { useEffect, useMemo } from 'react';
|
||||
import { RouteComponentProps } from 'react-router-dom';
|
||||
import fuzzy from 'fuzzy';
|
||||
import { Provider } from '@urbit/api';
|
||||
import { Provider, deSig } from '@urbit/api';
|
||||
import * as ob from 'urbit-ob';
|
||||
import { MatchItem, useLeapStore } from '../Nav';
|
||||
import { useAllies, useCharges } from '../../state/docket';
|
||||
import { ProviderList } from '../../components/ProviderList';
|
||||
@ -53,19 +54,34 @@ export const Providers = ({ match }: ProvidersProps) => {
|
||||
: [],
|
||||
[charges, search]
|
||||
);
|
||||
const results = useMemo(
|
||||
() =>
|
||||
allies
|
||||
? fuzzy
|
||||
.filter(
|
||||
search,
|
||||
Object.entries(allies).map(([ship]) => ship)
|
||||
)
|
||||
.sort(fuzzySort(search))
|
||||
.map((el) => ({ shipName: el.original, ...contacts[el.original] }))
|
||||
: [],
|
||||
[allies, search, contacts]
|
||||
);
|
||||
|
||||
const patp = `~${deSig(search) || ''}`;
|
||||
const isValidPatp = ob.isValidPatp(patp);
|
||||
|
||||
const results = useMemo(() => {
|
||||
if (!allies) {
|
||||
return [];
|
||||
}
|
||||
const exact =
|
||||
isValidPatp && !Object.keys(allies).includes(patp)
|
||||
? [
|
||||
{
|
||||
shipName: patp,
|
||||
...contacts[patp]
|
||||
}
|
||||
]
|
||||
: [];
|
||||
return [
|
||||
...exact,
|
||||
...fuzzy
|
||||
.filter(
|
||||
search,
|
||||
Object.entries(allies).map(([ship]) => ship)
|
||||
)
|
||||
.sort(fuzzySort(search))
|
||||
.map((el) => ({ shipName: el.original, ...contacts[el.original] }))
|
||||
];
|
||||
}, [allies, search, contacts]);
|
||||
|
||||
const count = results?.length;
|
||||
|
||||
@ -87,11 +103,22 @@ export const Providers = ({ match }: ProvidersProps) => {
|
||||
}))
|
||||
: [];
|
||||
|
||||
const newProviderMatches = isValidPatp
|
||||
? [
|
||||
{
|
||||
url: `/leap/search/${patp}/apps`,
|
||||
value: patp,
|
||||
display: patp,
|
||||
openInNewTab: false
|
||||
}
|
||||
]
|
||||
: [];
|
||||
|
||||
useLeapStore.setState({
|
||||
matches: ([] as MatchItem[]).concat(appMatches, providerMatches)
|
||||
matches: ([] as MatchItem[]).concat(appMatches, providerMatches, newProviderMatches)
|
||||
});
|
||||
}
|
||||
}, [results]);
|
||||
}, [results, patp]);
|
||||
|
||||
return (
|
||||
<div
|
||||
|
@ -19,7 +19,8 @@ import {
|
||||
docketInstall,
|
||||
ChargeUpdate,
|
||||
kilnRevive,
|
||||
kilnSuspend
|
||||
kilnSuspend,
|
||||
allyShip
|
||||
} from '@urbit/api';
|
||||
import api from './api';
|
||||
import { mockAllies, mockCharges, mockTreaties } from './mock-data';
|
||||
@ -50,6 +51,8 @@ interface DocketState {
|
||||
toggleDocket: (desk: string) => Promise<void>;
|
||||
installDocket: (ship: string, desk: string) => Promise<number | void>;
|
||||
uninstallDocket: (desk: string) => Promise<number | void>;
|
||||
//
|
||||
addAlly: (ship: string) => Promise<void>;
|
||||
}
|
||||
|
||||
const useDocketState = create<DocketState>((set, get) => ({
|
||||
@ -151,6 +154,12 @@ const useDocketState = create<DocketState>((set, get) => ({
|
||||
treaties: useMockData ? normalizeDockets(mockTreaties) : {},
|
||||
charges: {},
|
||||
allies: useMockData ? mockAllies : {},
|
||||
addAlly: async (ship) => {
|
||||
get().set((draft) => {
|
||||
draft.allies[ship] = [];
|
||||
});
|
||||
await api.poke(allyShip(ship));
|
||||
},
|
||||
set
|
||||
}));
|
||||
|
||||
@ -199,6 +208,35 @@ api.subscribe({
|
||||
}
|
||||
});
|
||||
|
||||
api.subscribe({
|
||||
app: 'treaty',
|
||||
path: '/treaties',
|
||||
event: (data: TreatyUpdate) => {
|
||||
console.log(data);
|
||||
|
||||
useDocketState.getState().set((draft) => {
|
||||
if ('add' in data) {
|
||||
const { ship, desk } = data.add;
|
||||
const treaty = normalizeDocket(data.add, desk);
|
||||
draft.treaties[`${ship}/${desk}`] = treaty;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
api.subscribe({
|
||||
app: 'treaty',
|
||||
path: '/allies',
|
||||
event: (data: TreatyUpdate) => {
|
||||
useDocketState.getState().set((draft) => {
|
||||
if ('new' in data) {
|
||||
const { ship, alliance } = data.new;
|
||||
draft.allies[ship] = alliance;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
const selCharges = (s: DocketState) => {
|
||||
return s.charges;
|
||||
};
|
||||
|
@ -53,3 +53,13 @@ export function docketInstall(ship: string, desk: string): Poke<any> {
|
||||
json: `${ship}/${desk}`
|
||||
};
|
||||
}
|
||||
|
||||
export function allyShip(ship: string): Poke<any> {
|
||||
return {
|
||||
app: 'treaty',
|
||||
mark: 'ally-update-0',
|
||||
json: {
|
||||
add: ship
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user