@swan-io/lake 7.0.8 → 7.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swan-io/lake",
3
- "version": "7.0.8",
3
+ "version": "7.1.1",
4
4
  "engines": {
5
5
  "node": ">=18.0.0",
6
6
  "yarn": "^1.22.0"
@@ -4,6 +4,7 @@ import { Pressable, StyleSheet, View } from "react-native";
4
4
  import { animations, backgroundColor, colors, radii, spacings } from "../constants/design";
5
5
  import { useBoolean } from "../hooks/useBoolean";
6
6
  import { useDebounce } from "../hooks/useDebounce";
7
+ import { isNotNullishOrEmpty } from "../utils/nullish";
7
8
  import { LakeButton } from "./LakeButton";
8
9
  import { LakeTextInput } from "./LakeTextInput";
9
10
  import { ResponsiveContainer } from "./ResponsiveContainer";
@@ -64,14 +65,14 @@ const CollapsibleSeachField = ({ inputRef, placeholder, initialValue, onChange,
64
65
  setFocused.on();
65
66
  }, pill: currentValue !== "" }), _jsx(TransitionView, { style: styles.openSearchFieldContainer, ...animations.fadeAndSlideInFromRight, children: hasFocus ? (_jsx(View, { style: styles.openSearchField, children: _jsx(ExpandedSearchField, { inputRef: inputRef, placeholder: placeholder, initialValue: initialValue, onChange: onChange, setFocused: setFocused, hasFocus: hasFocus, clear: clear, currentValue: currentValue, renderEnd: renderEnd }) })) : null })] }));
66
67
  };
67
- const ExpandedSearchField = ({ inputRef, placeholder, initialValue, onChange, setFocused, hasFocus, clear, renderEnd, }) => {
68
+ const ExpandedSearchField = ({ inputRef, placeholder, initialValue, onChange, setFocused, hasFocus, clear, renderEnd, currentValue, }) => {
68
69
  const timeoutRef = useRef(null);
69
- return (_jsx(LakeTextInput, { ref: inputRef, autoFocus: hasFocus, icon: "search-filled", placeholder: placeholder, defaultValue: initialValue, inputMode: "search", onChangeText: onChange, hideErrors: true, renderEnd: () => (_jsxs(_Fragment, { children: [_jsx(Pressable, { onPress: () => {
70
+ return (_jsx(LakeTextInput, { ref: inputRef, autoFocus: hasFocus, icon: "search-filled", placeholder: placeholder, defaultValue: initialValue, inputMode: "search", onChangeText: onChange, hideErrors: true, renderEnd: () => (_jsxs(_Fragment, { children: [isNotNullishOrEmpty(currentValue) && (_jsx(Pressable, { onPress: () => {
70
71
  if (timeoutRef.current != null) {
71
72
  clearTimeout(timeoutRef.current);
72
73
  }
73
74
  clear();
74
- }, style: styles.clearButton, children: _jsx(Svg, { viewBox: "0 0 16 16", style: styles.clear, children: _jsxs(_Fragment, { children: [_jsx(Line, { x1: "0", x2: "16", y1: "0", y2: "16", strokeLinecap: "round", stroke: colors.gray[500], strokeWidth: 2 }), _jsx(Line, { x1: "0", x2: "16", y1: "16", y2: "0", strokeLinecap: "round", stroke: colors.gray[500], strokeWidth: 2 })] }) }) }), renderEnd === null || renderEnd === void 0 ? void 0 : renderEnd()] })), onFocus: () => {
75
+ }, style: styles.clearButton, children: _jsx(Svg, { viewBox: "0 0 16 16", style: styles.clear, children: _jsxs(_Fragment, { children: [_jsx(Line, { x1: "0", x2: "16", y1: "0", y2: "16", strokeLinecap: "round", stroke: colors.gray[500], strokeWidth: 2 }), _jsx(Line, { x1: "0", x2: "16", y1: "16", y2: "0", strokeLinecap: "round", stroke: colors.gray[500], strokeWidth: 2 })] }) }) })), renderEnd === null || renderEnd === void 0 ? void 0 : renderEnd()] })), onFocus: () => {
75
76
  if (timeoutRef.current != null) {
76
77
  clearTimeout(timeoutRef.current);
77
78
  }
@@ -15,7 +15,7 @@ export const useAsyncDataSuspense = (asyncData) => {
15
15
  resolve(undefined);
16
16
  hasResolved.current = true;
17
17
  }
18
- });
18
+ }, [asyncData, resolve]);
19
19
  if (!hasResolved.current) {
20
20
  throw promiseToThrow;
21
21
  }
@@ -1,6 +1,6 @@
1
- import { AsyncData, Result } from "@swan-io/boxed";
1
+ import { AsyncData, Future, Result } from "@swan-io/boxed";
2
2
  import { DependencyList } from "react";
3
- import { AnyVariables, CombinedError, UseQueryArgs } from "urql";
3
+ import { AnyVariables, CombinedError, DocumentInput, UseQueryArgs } from "urql";
4
4
  type Query<Data> = {
5
5
  isForceReloading: boolean;
6
6
  data: AsyncData<Result<Data, CombinedError>>;
@@ -16,4 +16,9 @@ type PaginatedQuery<Data> = {
16
16
  setAfter: (cursor: string | undefined) => void;
17
17
  };
18
18
  export declare const useUrqlPaginatedQuery: <Data, Variables extends AnyVariables>(args: UseQueryArgs<Variables, Data>, dependencyList?: DependencyList) => PaginatedQuery<Data>;
19
+ type DeferredQuery<Data, Variables extends AnyVariables> = [
20
+ data: AsyncData<Result<Data, CombinedError>>,
21
+ query: (args: Variables) => Future<Result<Data, CombinedError>>
22
+ ];
23
+ export declare const useDeferredUrqlQuery: <Data, Variables extends AnyVariables>(document: DocumentInput<Data, Variables>) => DeferredQuery<Data, Variables>;
19
24
  export {};
@@ -1,7 +1,8 @@
1
- import { AsyncData, Result } from "@swan-io/boxed";
1
+ import { AsyncData, Future, Result } from "@swan-io/boxed";
2
2
  import { useCallback, useEffect, useMemo, useState } from "react";
3
- import { useQuery } from "urql";
3
+ import { useClient, useQuery, } from "urql";
4
4
  import { isNotNullish, isNullish } from "../utils/nullish";
5
+ import { parseOperationResult } from "../utils/urql";
5
6
  const EMPTY_DEPENDENCY_LIST = [];
6
7
  export const useUrqlQuery = (args, dependencyList = EMPTY_DEPENDENCY_LIST) => {
7
8
  const hasDependencyList = dependencyList !== EMPTY_DEPENDENCY_LIST;
@@ -81,3 +82,14 @@ export const useUrqlPaginatedQuery = (args, dependencyList = EMPTY_DEPENDENCY_LI
81
82
  setAfter,
82
83
  };
83
84
  };
85
+ export const useDeferredUrqlQuery = (document) => {
86
+ const [data, setData] = useState(AsyncData.NotAsked());
87
+ const client = useClient();
88
+ const query = useCallback((args) => {
89
+ setData(AsyncData.Loading());
90
+ return Future.fromPromise(client.query(document, args).toPromise().then(parseOperationResult)).tap(data => {
91
+ setData(AsyncData.Done(data));
92
+ });
93
+ }, [client, document]);
94
+ return [data, query];
95
+ };