Merge pull request #3130 from urbit/lf/base-hash

interface: show base hash
This commit is contained in:
matildepark 2020-07-15 20:31:14 -04:00 committed by GitHub
commit a40d8c0f92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 65 additions and 6 deletions

View File

@ -223,7 +223,28 @@
==
::
++ on-leave on-leave:def
++ on-peek on-peek:def
++ on-peek
|= =path
^- (unit (unit cage))
|^
?+ path (on-peek:def path)
[%x %clay %base %hash ~] ``hash+!>(base-hash)
==
:: stolen from +trouble
:: TODO: move to a lib?
++ base-hash
^- @uv
=+ .^ ota=(unit [=ship =desk =aeon:clay])
%gx /(scot %p our.bowl)/hood/(scot %da now.bowl)/kiln/ota/noun
==
?~ ota
*@uv
=/ parent (scot %p ship.u.ota)
=+ .^(=cass:clay %cs /[parent]/[desk.u.ota]/1/late/foo)
%^ end 3 3
.^(@uv %cz /[parent]/[desk.u.ota]/(scot %ud ud.cass))
--
++ on-agent on-agent:def
++ on-fail on-fail:def
--

View File

@ -41,7 +41,6 @@
++ on-leave on-leave:def
++ on-peek
|= =path
~& peeking=path
^- (unit (unit cage))
?+ path (on-peek:def path)
[* %kiln *] (on-peek:kiln-core path)

14
pkg/arvo/mar/hash.hoon Normal file
View File

@ -0,0 +1,14 @@
|_ hash=@uv
::
++ grad %noun
++ grow
|%
++ noun hash
++ json
s+(rsh 3 2 (scot %uv hash))
--
++ grab
|%
++ noun @uv
--
--

View File

@ -61,6 +61,7 @@ export default class App extends React.Component {
componentDidMount() {
this.subscription.start();
this.api.local.getBaseHash();
}
render() {

View File

@ -53,4 +53,8 @@ export default class BaseApi<S extends object = {}> {
);
});
}
scry<T>(app: string, path: Path): Promise<T> {
return fetch(`/~/scry/${app}${path}.json`).then(r => r.json() as Promise<T>);
}
}

View File

@ -2,9 +2,13 @@ import BaseApi from "./base";
import { StoreState } from "../store/type";
import { SelectedGroup } from "../types/local-update";
export default class LocalApi extends BaseApi<StoreState> {
getBaseHash() {
this.scry<string>('file-server', '/clay/base/hash').then(baseHash => {
this.store.handleEvent({ data: { local: { baseHash } } });
});
}
setSelected(selected: SelectedGroup[]) {
this.store.handleEvent({
data: {

View File

@ -24,6 +24,7 @@ export default class LaunchApp extends React.Component {
const { props } = this;
return (
<div className="h-100 flex flex-column h-100">
<div className='v-mid ph2 dtc-m dtc-l dtc-xl flex justify-between flex-wrap' style={{ maxWidth: '40rem' }}>
<Welcome firstTime={props.launch.firstTime} api={props.api} />
<Tiles
@ -34,6 +35,8 @@ export default class LaunchApp extends React.Component {
weather={props.weather}
/>
</div>
<div className="gray2-d gray2 ml4 mb4 f8"> {props.baseHash} </div>
</div>
);
}
}

View File

@ -3,7 +3,7 @@ import { StoreState } from '../store/type';
import { Cage } from '../types/cage';
import { LocalUpdate } from '../types/local-update';
type LocalState = Pick<StoreState, 'sidebarShown' | 'selectedGroups'>;
type LocalState = Pick<StoreState, 'sidebarShown' | 'selectedGroups' | 'baseHash'>;
export default class LocalReducer<S extends LocalState> {
reduce(json: Cage, state: S) {
@ -11,8 +11,14 @@ export default class LocalReducer<S extends LocalState> {
if (data) {
this.sidebarToggle(data, state);
this.setSelected(data, state);
this.baseHash(data, state);
}
}
baseHash(obj: LocalUpdate, state: S) {
if ('baseHash' in obj) {
state.baseHash = obj.baseHash;
}
}
sidebarToggle(obj: LocalUpdate, state: S) {
if ('sidebarToggle' in obj) {

View File

@ -38,6 +38,7 @@ export default class GlobalStore extends BaseStore<StoreState> {
pendingMessages: new Map(),
chatInitialized: false,
sidebarShown: true,
baseHash: null,
invites: {},
associations: {
chat: {},

View File

@ -16,6 +16,7 @@ export interface StoreState {
// local state
sidebarShown: boolean;
selectedGroups: SelectedGroup[];
baseHash: string | null;
// invite state
invites: Invites;
// metadata state

View File

@ -2,7 +2,8 @@ import { Path } from './noun';
export type LocalUpdate =
LocalUpdateSidebarToggle
| LocalUpdateSelectedGroups;
| LocalUpdateSelectedGroups
| LocalUpdateBaseHash;
interface LocalUpdateSidebarToggle {
sidebarToggle: boolean;
@ -12,4 +13,8 @@ interface LocalUpdateSelectedGroups {
selected: SelectedGroup[];
}
interface LocalUpdateBaseHash {
baseHash: string;
}
export type SelectedGroup = [Path, string];