mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-02 15:13:25 +03:00
metadata-fe: fix preview fetch
This commit is contained in:
parent
c90f7bde25
commit
ef0edb4939
@ -1,7 +1,7 @@
|
||||
import Urbit from '@urbit/http-api';
|
||||
const api = new Urbit('', '');
|
||||
api.ship = window.ship;
|
||||
api.verbose = true;
|
||||
// api.verbose = true;
|
||||
// @ts-ignore TODO window typings
|
||||
window.api = api;
|
||||
|
||||
|
@ -523,3 +523,19 @@ export const favicon = () => {
|
||||
});
|
||||
return svg;
|
||||
};
|
||||
|
||||
export function binaryIndexOf(arr: BigInteger[], target: BigInteger): number | undefined {
|
||||
let leftBound = 0;
|
||||
let rightBound = arr.length - 1;
|
||||
while(leftBound <= rightBound) {
|
||||
const halfway = Math.floor((leftBound + rightBound) / 2);
|
||||
if(arr[halfway].greater(target)) {
|
||||
leftBound = halfway + 1;
|
||||
} else if (arr[halfway].lesser(target)) {
|
||||
rightBound = halfway - 1;
|
||||
} else {
|
||||
return halfway;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
@ -39,9 +39,9 @@ const useMetadataState = createState<MetadataState>(
|
||||
if('metadata-hook-update' in preview) {
|
||||
const newState = get();
|
||||
newState.set((s) => {
|
||||
s.previews[group] = preview['metadata-hook-update'];
|
||||
s.previews[group] = preview['metadata-hook-update'].preview;
|
||||
});
|
||||
return preview['metadata-hook-update'];
|
||||
return preview['metadata-hook-update'].preview;
|
||||
} else {
|
||||
throw 'no-permissions';
|
||||
}
|
||||
@ -82,9 +82,11 @@ export function useAssocForGroup(group: string) {
|
||||
);
|
||||
}
|
||||
|
||||
const selPreview = (s: MetadataState) => [s.previews, s.getPreview] as const;
|
||||
|
||||
export function usePreview(group: string) {
|
||||
const [error, setError] = useState(null);
|
||||
const [previews, getPreview] = useMetadataState(s => [s.previews, s.getPreview]);
|
||||
const [previews, getPreview] = useMetadataState(selPreview);
|
||||
useEffect(() => {
|
||||
let mounted = true;
|
||||
(async () => {
|
||||
@ -100,7 +102,7 @@ export function usePreview(group: string) {
|
||||
return () => {
|
||||
mounted = false;
|
||||
};
|
||||
});
|
||||
}, [group]);
|
||||
|
||||
const preview = previews[group];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user