mirror of
https://github.com/dergigi/boris.git
synced 2025-12-27 19:44:40 +01:00
- Add project structure with TypeScript, React, and Vite - Implement nostr authentication using browser extension (NIP-07) - Add NIP-51 compliant bookmark fetching and display - Create minimal UI with login and bookmark components - Integrate applesauce-core and applesauce-react libraries - Add responsive styling with dark/light mode support - Include comprehensive README with setup instructions This is a minimal MVP for a nostr bookmark client that allows users to view their bookmarks according to NIP-51 specification.
47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
import { useRef } from "react";
|
|
import { Observable, NEVER } from "rxjs";
|
|
import { catchError, switchMap } from "rxjs/operators";
|
|
import { useForceUpdate } from "./helpers";
|
|
import { useObservable } from "./use-observable";
|
|
|
|
/**
|
|
* Enhance an Observable by making errors catch-able to ErrorBoundary.
|
|
*
|
|
* It catches Observable error and re-throw it as React render error.
|
|
*
|
|
* @template TInput Input value within Observable.
|
|
*
|
|
* @param input$ Input Observable.
|
|
* @returns Observable with the same input type
|
|
*/
|
|
export function useRenderThrow<TInput>(
|
|
input$: Observable<TInput>
|
|
): Observable<TInput> {
|
|
const forceUpdate = useForceUpdate();
|
|
const errorRef = useRef<Error | null>();
|
|
|
|
const output$ = useObservable(
|
|
inputs$ =>
|
|
inputs$.pipe(
|
|
switchMap(([input$]) => {
|
|
errorRef.current = null;
|
|
return input$.pipe(
|
|
catchError(error => {
|
|
errorRef.current = error;
|
|
forceUpdate();
|
|
return NEVER;
|
|
})
|
|
);
|
|
})
|
|
),
|
|
[input$]
|
|
);
|
|
|
|
if (errorRef.current) {
|
|
// Let error boundary catch the error
|
|
throw errorRef.current;
|
|
}
|
|
|
|
return output$;
|
|
}
|