metadata-fe: fix preview fetch

This commit is contained in:
Liam Fitzgerald 2021-06-15 12:11:23 +10:00
parent c90f7bde25
commit ef0edb4939
No known key found for this signature in database
GPG Key ID: D390E12C61D1CFFB
3 changed files with 23 additions and 5 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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];