mirror of
https://github.com/urbit/shrub.git
synced 2025-01-06 04:07:23 +03:00
Merge branch 'master' into next/vere
This commit is contained in:
commit
30c329115d
@ -1,10 +1,10 @@
|
|||||||
:~ title+'System'
|
:~ title+'System'
|
||||||
info+'An app launcher for Urbit.'
|
info+'An app launcher for Urbit.'
|
||||||
color+0xee.5432
|
color+0xee.5432
|
||||||
glob-http+['https://bootstrap.urbit.org/glob-0vcggb9.v4sgp.jbo30.t34mk.58i52.glob' 0vcggb9.v4sgp.jbo30.t34mk.58i52]
|
glob-http+['https://bootstrap.urbit.org/glob-0v4.t104r.h4pr1.kc9bu.0f8nq.urrhk.glob' 0v4.t104r.h4pr1.kc9bu.0f8nq.urrhk]
|
||||||
::glob-ames+~zod^0v0
|
::glob-ames+~zod^0v0
|
||||||
base+'grid'
|
base+'grid'
|
||||||
version+[1 1 0]
|
version+[1 1 2]
|
||||||
website+'https://tlon.io'
|
website+'https://tlon.io'
|
||||||
license+'MIT'
|
license+'MIT'
|
||||||
==
|
==
|
||||||
|
@ -10,7 +10,7 @@ import useContactState from './state/contact';
|
|||||||
import api from './state/api';
|
import api from './state/api';
|
||||||
import { useMedia } from './logic/useMedia';
|
import { useMedia } from './logic/useMedia';
|
||||||
import { useHarkStore } from './state/hark';
|
import { useHarkStore } from './state/hark';
|
||||||
import { useTheme } from './state/settings';
|
import { useSettingsState, useTheme } from './state/settings';
|
||||||
import { useLocalState } from './state/local';
|
import { useLocalState } from './state/local';
|
||||||
import { ErrorAlert } from './components/ErrorAlert';
|
import { ErrorAlert } from './components/ErrorAlert';
|
||||||
import { useErrorHandler } from './logic/useErrorHandler';
|
import { useErrorHandler } from './logic/useErrorHandler';
|
||||||
@ -53,6 +53,10 @@ const AppRoutes = () => {
|
|||||||
handleError(() => {
|
handleError(() => {
|
||||||
window.name = 'grid';
|
window.name = 'grid';
|
||||||
|
|
||||||
|
const { initialize: settingsInitialize, fetchAll } = useSettingsState.getState();
|
||||||
|
settingsInitialize(api);
|
||||||
|
fetchAll();
|
||||||
|
|
||||||
const { fetchDefaultAlly, fetchAllies, fetchCharges } = useDocketState.getState();
|
const { fetchDefaultAlly, fetchAllies, fetchCharges } = useDocketState.getState();
|
||||||
fetchDefaultAlly();
|
fetchDefaultAlly();
|
||||||
fetchCharges();
|
fetchCharges();
|
||||||
|
@ -3,7 +3,7 @@ import { RouteComponentProps } from 'react-router-dom';
|
|||||||
import fuzzy from 'fuzzy';
|
import fuzzy from 'fuzzy';
|
||||||
import { Treaty } from '@urbit/api';
|
import { Treaty } from '@urbit/api';
|
||||||
import { ShipName } from '../../components/ShipName';
|
import { ShipName } from '../../components/ShipName';
|
||||||
import useDocketState, { useAllyTreaties, useAllies } from '../../state/docket';
|
import { useAllyTreaties } from '../../state/docket';
|
||||||
import { useLeapStore } from '../Nav';
|
import { useLeapStore } from '../Nav';
|
||||||
import { AppList } from '../../components/AppList';
|
import { AppList } from '../../components/AppList';
|
||||||
import { addRecentDev } from './Home';
|
import { addRecentDev } from './Home';
|
||||||
@ -19,14 +19,12 @@ export const Apps = ({ match }: AppsProps) => {
|
|||||||
}));
|
}));
|
||||||
const provider = match?.params.ship;
|
const provider = match?.params.ship;
|
||||||
const { treaties, status } = useAllyTreaties(provider);
|
const { treaties, status } = useAllyTreaties(provider);
|
||||||
const allies = useAllies();
|
|
||||||
const isAllied = provider in allies;
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (Object.keys(allies).length > 0 && !isAllied) {
|
if (provider) {
|
||||||
useDocketState.getState().addAlly(provider);
|
addRecentDev(provider);
|
||||||
}
|
}
|
||||||
}, [allies, isAllied, provider]);
|
}, [provider]);
|
||||||
|
|
||||||
const results = useMemo(() => {
|
const results = useMemo(() => {
|
||||||
if (!treaties) {
|
if (!treaties) {
|
||||||
@ -74,12 +72,8 @@ export const Apps = ({ match }: AppsProps) => {
|
|||||||
}
|
}
|
||||||
}, [results]);
|
}, [results]);
|
||||||
|
|
||||||
useEffect(() => {
|
const showNone =
|
||||||
if (provider) {
|
status === 'error' || ((status === 'success' || status === 'initial') && results?.length === 0);
|
||||||
useDocketState.getState().fetchAllyTreaties(provider);
|
|
||||||
addRecentDev(provider);
|
|
||||||
}
|
|
||||||
}, [provider]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="dialog-inner-container md:px-6 md:py-8 h4 text-gray-400">
|
<div className="dialog-inner-container md:px-6 md:py-8 h4 text-gray-400">
|
||||||
@ -107,12 +101,11 @@ export const Apps = ({ match }: AppsProps) => {
|
|||||||
<p>That's it!</p>
|
<p>That's it!</p>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
{status === 'error' ||
|
{showNone && (
|
||||||
((status === 'success' || status === 'initial') && results?.length === 0 && (
|
<h2>
|
||||||
<h2>
|
Unable to find software developed by <ShipName name={provider} className="font-mono" />
|
||||||
Unable to find software developed by <ShipName name={provider} className="font-mono" />
|
</h2>
|
||||||
</h2>
|
)}
|
||||||
))}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import create, { SetState } from 'zustand';
|
import create, { SetState } from 'zustand';
|
||||||
import produce from 'immer';
|
import produce from 'immer';
|
||||||
import { useCallback, useEffect } from 'react';
|
import { useCallback, useEffect, useState } from 'react';
|
||||||
import { omit, pick } from 'lodash';
|
import { omit, pick } from 'lodash';
|
||||||
import {
|
import {
|
||||||
Allies,
|
Allies,
|
||||||
@ -27,7 +27,7 @@ import {
|
|||||||
import api from './api';
|
import api from './api';
|
||||||
import { mockAllies, mockCharges, mockTreaties } from './mock-data';
|
import { mockAllies, mockCharges, mockTreaties } from './mock-data';
|
||||||
import { fakeRequest, normalizeUrbitColor, useMockData } from './util';
|
import { fakeRequest, normalizeUrbitColor, useMockData } from './util';
|
||||||
import { useAsyncCall } from '../logic/useAsyncCall';
|
import { Status } from '../logic/useAsyncCall';
|
||||||
|
|
||||||
export interface ChargeWithDesk extends Charge {
|
export interface ChargeWithDesk extends Charge {
|
||||||
desk: string;
|
desk: string;
|
||||||
@ -269,17 +269,38 @@ export function useAllies() {
|
|||||||
|
|
||||||
export function useAllyTreaties(ship: string) {
|
export function useAllyTreaties(ship: string) {
|
||||||
const allies = useAllies();
|
const allies = useAllies();
|
||||||
const { call: fetchTreaties, status } = useAsyncCall(() =>
|
const isAllied = ship in allies;
|
||||||
useDocketState.getState().fetchAllyTreaties(ship)
|
const [status, setStatus] = useState<Status>('initial');
|
||||||
);
|
const [treaties, setTreaties] = useState<Treaties>();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (ship in allies) {
|
if (Object.keys(allies).length > 0 && !isAllied) {
|
||||||
fetchTreaties();
|
setStatus('loading');
|
||||||
|
useDocketState.getState().addAlly(ship);
|
||||||
}
|
}
|
||||||
}, [ship, allies]);
|
}, [allies, isAllied, ship]);
|
||||||
|
|
||||||
const treaties = useDocketState(
|
useEffect(() => {
|
||||||
|
async function fetchTreaties() {
|
||||||
|
if (isAllied) {
|
||||||
|
setStatus('loading');
|
||||||
|
try {
|
||||||
|
const newTreaties = await useDocketState.getState().fetchAllyTreaties(ship);
|
||||||
|
|
||||||
|
if (Object.keys(newTreaties).length > 0) {
|
||||||
|
setTreaties(newTreaties);
|
||||||
|
setStatus('success');
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
setStatus('error');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fetchTreaties();
|
||||||
|
}, [ship, isAllied]);
|
||||||
|
|
||||||
|
const storeTreaties = useDocketState(
|
||||||
useCallback(
|
useCallback(
|
||||||
(s) => {
|
(s) => {
|
||||||
const charter = s.allies[ship];
|
const charter = s.allies[ship];
|
||||||
@ -289,7 +310,24 @@ export function useAllyTreaties(ship: string) {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const timeout = setTimeout(() => {
|
||||||
|
setStatus('error');
|
||||||
|
}, 30 * 1000); // wait 30 secs before timing out
|
||||||
|
|
||||||
|
if (Object.keys(storeTreaties).length > 0) {
|
||||||
|
setTreaties(storeTreaties);
|
||||||
|
setStatus('success');
|
||||||
|
clearTimeout(timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
clearTimeout(timeout);
|
||||||
|
};
|
||||||
|
}, [storeTreaties]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
isAllied,
|
||||||
treaties,
|
treaties,
|
||||||
status
|
status
|
||||||
};
|
};
|
||||||
|
@ -24,7 +24,9 @@ interface BaseSettingsState {
|
|||||||
tiles: {
|
tiles: {
|
||||||
order: string[];
|
order: string[];
|
||||||
};
|
};
|
||||||
|
loaded: boolean;
|
||||||
putEntry: (bucket: string, key: string, value: Value) => Promise<void>;
|
putEntry: (bucket: string, key: string, value: Value) => Promise<void>;
|
||||||
|
fetchAll: () => Promise<void>;
|
||||||
[ref: string]: unknown;
|
[ref: string]: unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,8 +87,8 @@ export const useSettingsState = createState<BaseSettingsState>(
|
|||||||
fetchAll: async () => {
|
fetchAll: async () => {
|
||||||
const result = (await api.scry<DeskData>(getDeskSettings(window.desk))).desk;
|
const result = (await api.scry<DeskData>(getDeskSettings(window.desk))).desk;
|
||||||
const newState = {
|
const newState = {
|
||||||
loaded: true,
|
..._.mergeWith(get(), result, (obj, src) => (_.isArray(src) ? src : undefined)),
|
||||||
..._.mergeWith(get(), result, (obj, src) => (_.isArray(src) ? src : undefined))
|
loaded: true
|
||||||
};
|
};
|
||||||
set(newState);
|
set(newState);
|
||||||
}
|
}
|
||||||
@ -98,6 +100,7 @@ export const useSettingsState = createState<BaseSettingsState>(
|
|||||||
const data = _.get(e, 'settings-event', false);
|
const data = _.get(e, 'settings-event', false);
|
||||||
if (data) {
|
if (data) {
|
||||||
reduceStateN(get(), data, reduceUpdate);
|
reduceStateN(get(), data, reduceUpdate);
|
||||||
|
set({ loaded: true });
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
|
@ -25,24 +25,38 @@ export const dragTypes = {
|
|||||||
TILE: 'tile'
|
TILE: 'tile'
|
||||||
};
|
};
|
||||||
|
|
||||||
export const selTiles = (s: SettingsState) => s.tiles;
|
export const selTiles = (s: SettingsState) => ({
|
||||||
|
order: s.tiles.order,
|
||||||
|
loaded: s.loaded
|
||||||
|
});
|
||||||
|
|
||||||
export const TileGrid = ({ menu }: TileGridProps) => {
|
export const TileGrid = ({ menu }: TileGridProps) => {
|
||||||
const charges = useCharges();
|
const charges = useCharges();
|
||||||
const chargesLoaded = Object.keys(charges).length > 0;
|
const chargesLoaded = Object.keys(charges).length > 0;
|
||||||
const { order } = useSettingsState(selTiles);
|
const { order, loaded } = useSettingsState(selTiles);
|
||||||
const isMobile = useMedia('(pointer: coarse)');
|
const isMobile = useMedia('(pointer: coarse)');
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const hasKeys = order && !!order.length;
|
const hasKeys = order && !!order.length;
|
||||||
const chargeKeys = Object.keys(charges);
|
const chargeKeys = Object.keys(charges);
|
||||||
|
const hasChargeKeys = chargeKeys.length > 0;
|
||||||
|
|
||||||
if (!hasKeys) {
|
if (!loaded) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Correct order state, fill if none, remove duplicates, and remove
|
||||||
|
// old uninstalled app keys
|
||||||
|
if (!hasKeys && hasChargeKeys) {
|
||||||
useSettingsState.getState().putEntry('tiles', 'order', chargeKeys);
|
useSettingsState.getState().putEntry('tiles', 'order', chargeKeys);
|
||||||
} else if (order.length < chargeKeys.length) {
|
} else if (order.length < chargeKeys.length) {
|
||||||
useSettingsState.getState().putEntry('tiles', 'order', uniq(order.concat(chargeKeys)));
|
useSettingsState.getState().putEntry('tiles', 'order', uniq(order.concat(chargeKeys)));
|
||||||
|
} else if (order.length > chargeKeys.length && hasChargeKeys) {
|
||||||
|
useSettingsState
|
||||||
|
.getState()
|
||||||
|
.putEntry('tiles', 'order', uniq(order.filter((key) => key in charges).concat(chargeKeys)));
|
||||||
}
|
}
|
||||||
}, [charges, order]);
|
}, [charges, order, loaded]);
|
||||||
|
|
||||||
if (!chargesLoaded) {
|
if (!chargesLoaded) {
|
||||||
return <span>Loading...</span>;
|
return <span>Loading...</span>;
|
||||||
@ -65,10 +79,10 @@ export const TileGrid = ({ menu }: TileGridProps) => {
|
|||||||
>
|
>
|
||||||
<div className="grid justify-center grid-cols-2 sm:grid-cols-[repeat(auto-fit,minmax(auto,250px))] gap-4 px-4 md:px-8 w-full max-w-6xl">
|
<div className="grid justify-center grid-cols-2 sm:grid-cols-[repeat(auto-fit,minmax(auto,250px))] gap-4 px-4 md:px-8 w-full max-w-6xl">
|
||||||
{order
|
{order
|
||||||
.filter((d) => d !== window.desk)
|
.filter((d) => d !== window.desk && d in charges)
|
||||||
.map((desk) => (
|
.map((desk) => (
|
||||||
<TileContainer desk={desk}>
|
<TileContainer key={desk} desk={desk}>
|
||||||
<Tile key={desk} charge={charges[desk]} desk={desk} disabled={menu === 'upgrading'} />
|
<Tile charge={charges[desk]} desk={desk} disabled={menu === 'upgrading'} />
|
||||||
</TileContainer>
|
</TileContainer>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user