@relaycast/react 0.1.2
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/dist/context.d.ts +10 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +4 -0
- package/dist/context.js.map +1 -0
- package/dist/hooks/useAgent.d.ts +3 -0
- package/dist/hooks/useAgent.d.ts.map +1 -0
- package/dist/hooks/useAgent.js +9 -0
- package/dist/hooks/useAgent.js.map +1 -0
- package/dist/hooks/useChannel.d.ts +3 -0
- package/dist/hooks/useChannel.d.ts.map +1 -0
- package/dist/hooks/useChannel.js +32 -0
- package/dist/hooks/useChannel.js.map +1 -0
- package/dist/hooks/useChannels.d.ts +3 -0
- package/dist/hooks/useChannels.d.ts.map +1 -0
- package/dist/hooks/useChannels.js +31 -0
- package/dist/hooks/useChannels.js.map +1 -0
- package/dist/hooks/useDMs.d.ts +3 -0
- package/dist/hooks/useDMs.d.ts.map +1 -0
- package/dist/hooks/useDMs.js +44 -0
- package/dist/hooks/useDMs.js.map +1 -0
- package/dist/hooks/useEvent.d.ts +4 -0
- package/dist/hooks/useEvent.d.ts.map +1 -0
- package/dist/hooks/useEvent.js +16 -0
- package/dist/hooks/useEvent.js.map +1 -0
- package/dist/hooks/useInbox.d.ts +3 -0
- package/dist/hooks/useInbox.d.ts.map +1 -0
- package/dist/hooks/useInbox.js +35 -0
- package/dist/hooks/useInbox.js.map +1 -0
- package/dist/hooks/useMessages.d.ts +3 -0
- package/dist/hooks/useMessages.d.ts.map +1 -0
- package/dist/hooks/useMessages.js +46 -0
- package/dist/hooks/useMessages.js.map +1 -0
- package/dist/hooks/usePresence.d.ts +3 -0
- package/dist/hooks/usePresence.d.ts.map +1 -0
- package/dist/hooks/usePresence.js +31 -0
- package/dist/hooks/usePresence.js.map +1 -0
- package/dist/hooks/useReaction.d.ts +3 -0
- package/dist/hooks/useReaction.d.ts.map +1 -0
- package/dist/hooks/useReaction.js +15 -0
- package/dist/hooks/useReaction.js.map +1 -0
- package/dist/hooks/useRelay.d.ts +3 -0
- package/dist/hooks/useRelay.d.ts.map +1 -0
- package/dist/hooks/useRelay.js +9 -0
- package/dist/hooks/useRelay.js.map +1 -0
- package/dist/hooks/useReply.d.ts +3 -0
- package/dist/hooks/useReply.d.ts.map +1 -0
- package/dist/hooks/useReply.js +27 -0
- package/dist/hooks/useReply.js.map +1 -0
- package/dist/hooks/useSearch.d.ts +8 -0
- package/dist/hooks/useSearch.d.ts.map +1 -0
- package/dist/hooks/useSearch.js +36 -0
- package/dist/hooks/useSearch.js.map +1 -0
- package/dist/hooks/useSendDM.d.ts +3 -0
- package/dist/hooks/useSendDM.d.ts.map +1 -0
- package/dist/hooks/useSendDM.js +19 -0
- package/dist/hooks/useSendDM.js.map +1 -0
- package/dist/hooks/useSendMessage.d.ts +3 -0
- package/dist/hooks/useSendMessage.d.ts.map +1 -0
- package/dist/hooks/useSendMessage.js +27 -0
- package/dist/hooks/useSendMessage.js.map +1 -0
- package/dist/hooks/useThread.d.ts +3 -0
- package/dist/hooks/useThread.d.ts.map +1 -0
- package/dist/hooks/useThread.js +31 -0
- package/dist/hooks/useThread.js.map +1 -0
- package/dist/hooks/useWebSocket.d.ts +6 -0
- package/dist/hooks/useWebSocket.d.ts.map +1 -0
- package/dist/hooks/useWebSocket.js +11 -0
- package/dist/hooks/useWebSocket.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/provider.d.ts +10 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +47 -0
- package/dist/provider.js.map +1 -0
- package/dist/reducer.d.ts +4 -0
- package/dist/reducer.d.ts.map +1 -0
- package/dist/reducer.js +265 -0
- package/dist/reducer.js.map +1 -0
- package/dist/store.d.ts +3 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +64 -0
- package/dist/store.js.map +1 -0
- package/dist/types.d.ts +121 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +45 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Relay, AgentClient, WsClient } from '@relaycast/sdk';
|
|
2
|
+
import type { RelayStore } from './types.js';
|
|
3
|
+
export interface ClientContextValue {
|
|
4
|
+
relay: Relay;
|
|
5
|
+
agent: AgentClient;
|
|
6
|
+
ws: WsClient;
|
|
7
|
+
}
|
|
8
|
+
export declare const ClientContext: import("react").Context<ClientContextValue | null>;
|
|
9
|
+
export declare const StoreContext: import("react").Context<RelayStore | null>;
|
|
10
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,KAAK,CAAC;IACb,KAAK,EAAE,WAAW,CAAC;IACnB,EAAE,EAAE,QAAQ,CAAC;CACd;AAED,eAAO,MAAM,aAAa,oDAAiD,CAAC;AAE5E,eAAO,MAAM,YAAY,4CAAyC,CAAC"}
|
package/dist/context.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAUtC,MAAM,CAAC,MAAM,aAAa,GAAG,aAAa,CAA4B,IAAI,CAAC,CAAC;AAE5E,MAAM,CAAC,MAAM,YAAY,GAAG,aAAa,CAAoB,IAAI,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAgent.d.ts","sourceRoot":"","sources":["../../src/hooks/useAgent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAGlD,wBAAgB,QAAQ,IAAI,WAAW,CAItC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { useContext } from 'react';
|
|
2
|
+
import { ClientContext } from '../context.js';
|
|
3
|
+
export function useAgent() {
|
|
4
|
+
const ctx = useContext(ClientContext);
|
|
5
|
+
if (!ctx)
|
|
6
|
+
throw new Error('useAgent must be used within <RelayProvider>');
|
|
7
|
+
return ctx.agent;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=useAgent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAgent.js","sourceRoot":"","sources":["../../src/hooks/useAgent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAEnC,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,MAAM,UAAU,QAAQ;IACtB,MAAM,GAAG,GAAG,UAAU,CAAC,aAAa,CAAC,CAAC;IACtC,IAAI,CAAC,GAAG;QAAE,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IAC1E,OAAO,GAAG,CAAC,KAAK,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useChannel.d.ts","sourceRoot":"","sources":["../../src/hooks/useChannel.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAiB,MAAM,aAAa,CAAC;AAInE,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,CAiCzD"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useContext, useEffect, useSyncExternalStore } from 'react';
|
|
2
|
+
import { ClientContext, StoreContext } from '../context.js';
|
|
3
|
+
const EMPTY = { channel: null, members: [], loading: true, error: null };
|
|
4
|
+
export function useChannel(name) {
|
|
5
|
+
const ctx = useContext(ClientContext);
|
|
6
|
+
const store = useContext(StoreContext);
|
|
7
|
+
if (!ctx || !store)
|
|
8
|
+
throw new Error('useChannel must be used within <RelayProvider>');
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
store.updateChannelDetail(name, (prev) => ({ ...prev, loading: true }));
|
|
11
|
+
ctx.agent.channels.get(name)
|
|
12
|
+
.then((result) => {
|
|
13
|
+
const { members, ...channel } = result;
|
|
14
|
+
store.updateChannelDetail(name, () => ({ channel, members, loading: false, error: null }));
|
|
15
|
+
})
|
|
16
|
+
.catch((error) => {
|
|
17
|
+
store.updateChannelDetail(name, (prev) => ({
|
|
18
|
+
...prev,
|
|
19
|
+
loading: false,
|
|
20
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
21
|
+
}));
|
|
22
|
+
});
|
|
23
|
+
}, [name, ctx.agent, store]);
|
|
24
|
+
const data = useSyncExternalStore(store.subscribe, () => store.getState().channelDetails[name] ?? EMPTY);
|
|
25
|
+
return {
|
|
26
|
+
channel: data.channel,
|
|
27
|
+
members: data.members,
|
|
28
|
+
loading: data.loading,
|
|
29
|
+
error: data.error,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=useChannel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useChannel.js","sourceRoot":"","sources":["../../src/hooks/useChannel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAG5D,MAAM,KAAK,GAAkB,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAExF,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,MAAM,GAAG,GAAG,UAAU,CAAC,aAAa,CAAC,CAAC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AI,CAAC,IAAI,KAAK,CACrD,CAAC;IAEF,OAAO;QACL,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,KAAK,EAAE,IAAI,CAAC,KAAK;KAClB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useChannels.d.ts","sourceRoot":"","sources":["../../src/hooks/useChannels.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD,wBAAgB,WAAW,IAAI,iBAAiB,CAiC/C"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { useContext, useEffect, useSyncExternalStore } from 'react';
|
|
2
|
+
import { ClientContext, StoreContext } from '../context.js';
|
|
3
|
+
export function useChannels() {
|
|
4
|
+
const ctx = useContext(ClientContext);
|
|
5
|
+
const store = useContext(StoreContext);
|
|
6
|
+
if (!ctx || !store)
|
|
7
|
+
throw new Error('useChannels must be used within <RelayProvider>');
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
store.setState({ channels: { ...store.getState().channels, loading: true } });
|
|
10
|
+
ctx.agent.channels.list()
|
|
11
|
+
.then((data) => {
|
|
12
|
+
store.setState({ channels: { data, loading: false, error: null } });
|
|
13
|
+
})
|
|
14
|
+
.catch((error) => {
|
|
15
|
+
store.setState({
|
|
16
|
+
channels: {
|
|
17
|
+
...store.getState().channels,
|
|
18
|
+
loading: false,
|
|
19
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
}, [ctx.agent, store]);
|
|
24
|
+
const state = useSyncExternalStore(store.subscribe, () => store.getState().channels);
|
|
25
|
+
return {
|
|
26
|
+
channels: state.data,
|
|
27
|
+
loading: state.loading,
|
|
28
|
+
error: state.error,
|
|
29
|
+
};
|
|
30
|
+
}
|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;aACF,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACP,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;IAEvB,MAAM,KAAK,GAAG,oBAAoB,CAChC,KAAK,CAAC,SAAS,EACf,GAAG,EAAE,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAChC,CAAC;IAEF,OAAO;QACL,QAAQ,EAAE,KAAK,CAAC,IAAI;QACpB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,KAAK,EAAE,KAAK,CAAC,KAAK;KACnB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDMs.d.ts","sourceRoot":"","sources":["../../src/hooks/useDMs.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,wBAAgB,MAAM,IAAI,YAAY,CA8CrC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { useContext, useEffect, useSyncExternalStore } from 'react';
|
|
2
|
+
import { ClientContext, StoreContext } from '../context.js';
|
|
3
|
+
export function useDMs() {
|
|
4
|
+
const ctx = useContext(ClientContext);
|
|
5
|
+
const store = useContext(StoreContext);
|
|
6
|
+
if (!ctx || !store)
|
|
7
|
+
throw new Error('useDMs must be used within <RelayProvider>');
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
store.setState({ dms: { ...store.getState().dms, loading: true } });
|
|
10
|
+
ctx.agent.dms.conversations()
|
|
11
|
+
.then((data) => {
|
|
12
|
+
store.setState({ dms: { data, loading: false, error: null } });
|
|
13
|
+
})
|
|
14
|
+
.catch((error) => {
|
|
15
|
+
store.setState({
|
|
16
|
+
dms: {
|
|
17
|
+
...store.getState().dms,
|
|
18
|
+
loading: false,
|
|
19
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
}, [ctx.agent, store]);
|
|
24
|
+
// Refetch when DM events flag loading: true
|
|
25
|
+
const state = useSyncExternalStore(store.subscribe, () => store.getState().dms);
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (!state.loading)
|
|
28
|
+
return;
|
|
29
|
+
ctx.agent.dms.conversations()
|
|
30
|
+
.then((data) => {
|
|
31
|
+
store.setState({ dms: { data, loading: false, error: null } });
|
|
32
|
+
})
|
|
33
|
+
.catch(() => {
|
|
34
|
+
// Silently fail on refetch — keep existing data
|
|
35
|
+
store.setState({ dms: { ...store.getState().dms, loading: false } });
|
|
36
|
+
});
|
|
37
|
+
}, [state.loading, ctx.agent, store]);
|
|
38
|
+
return {
|
|
39
|
+
conversations: state.data,
|
|
40
|
+
loading: state.loading,
|
|
41
|
+
error: state.error,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=useDMs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDMs.js","sourceRoot":"","sources":["../../src/hooks/useDMs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAG5D,MAAM,UAAU,MAAM;IACpB,MAAM,GAAG,GAAG,UAAU,CAAC,aAAa,CAAC,CAAC;IACtC,MAAM,KAAK,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;IACvC,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAElF,SAAS,CAAC,GAAG,EAAE;QACb,KAAK,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,EAAE,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;QAEpE,GAAG,CAAC,KAAK,CAAC,GA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GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;QACvE,CAAC,CAAC,CAAC;IACP,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;IAEtC,OAAO;QACL,aAAa,EAAE,KAAK,CAAC,IAAI;QACzB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,KAAK,EAAE,KAAK,CAAC,KAAK;KACnB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useEvent.d.ts","sourceRoot":"","sources":["../../src/hooks/useEvent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAGnD,wBAAgB,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,CAAC,WAAW,CAAC,GAAG,IAAI,CAapF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useContext, useEffect, useRef } from 'react';
|
|
2
|
+
import { ClientContext } from '../context.js';
|
|
3
|
+
export function useEvent(eventType, handler) {
|
|
4
|
+
const ctx = useContext(ClientContext);
|
|
5
|
+
if (!ctx)
|
|
6
|
+
throw new Error('useEvent must be used within <RelayProvider>');
|
|
7
|
+
const handlerRef = useRef(handler);
|
|
8
|
+
handlerRef.current = handler;
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
const off = ctx.ws.on(eventType, (event) => {
|
|
11
|
+
handlerRef.current(event);
|
|
12
|
+
});
|
|
13
|
+
return off;
|
|
14
|
+
}, [eventType, ctx.ws]);
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=useEvent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useEvent.js","sourceRoot":"","sources":["../../src/hooks/useEvent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAGtD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,MAAM,UAAU,QAAQ,CAAC,SAAiB,EAAE,OAAkC;IAC5E,MAAM,GAAG,GAAG,UAAU,CAAC,aAAa,CAAC,CAAC;IACtC,IAAI,CAAC,GAAG;QAAE,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IAE1E,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IACnC,UAAU,CAAC,OAAO,GAAG,OAAO,CAAC;IAE7B,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,GAAG,GAAG,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE;YACzC,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAC5B,CAAC,CAAC,CAAC;QACH,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useInbox.d.ts","sourceRoot":"","sources":["../../src/hooks/useInbox.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,wBAAgB,QAAQ,IAAI,cAAc,CAoCzC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { useContext, useEffect, useCallback, useSyncExternalStore } from 'react';
|
|
2
|
+
import { ClientContext, StoreContext } from '../context.js';
|
|
3
|
+
export function useInbox() {
|
|
4
|
+
const ctx = useContext(ClientContext);
|
|
5
|
+
const store = useContext(StoreContext);
|
|
6
|
+
if (!ctx || !store)
|
|
7
|
+
throw new Error('useInbox must be used within <RelayProvider>');
|
|
8
|
+
const fetchInbox = useCallback(async () => {
|
|
9
|
+
store.setState({ inbox: { ...store.getState().inbox, loading: true } });
|
|
10
|
+
try {
|
|
11
|
+
const data = await ctx.agent.inbox();
|
|
12
|
+
store.setState({ inbox: { data, loading: false, error: null } });
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
store.setState({
|
|
16
|
+
inbox: {
|
|
17
|
+
...store.getState().inbox,
|
|
18
|
+
loading: false,
|
|
19
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}, [ctx.agent, store]);
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
void fetchInbox();
|
|
26
|
+
}, [fetchInbox]);
|
|
27
|
+
const state = useSyncExternalStore(store.subscribe, () => store.getState().inbox);
|
|
28
|
+
return {
|
|
29
|
+
inbox: state.data,
|
|
30
|
+
loading: state.loading,
|
|
31
|
+
error: state.error,
|
|
32
|
+
refresh: fetchInbox,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=useInbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useInbox.js","sourceRoot":"","sources":["../../src/hooks/useInbox.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AACjF,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAG5D,MAAM,UAAU,QAAQ;IACtB,MAAM,GAAG,GAAG,UAAU,CAAC,aAAa,CAAC,CAAC;IACtC,MAAM,KAAK,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;IACvC,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IAEpF,MAAM,UAAU,GAAG,WAAW,CAAC,KAAK,IAAI,EAAE;QACxC,KAAK,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,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appings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAmB,MAAM,aAAa,CAAC;AAItE,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,iBAAiB,CAgD9D"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { useContext, useEffect, useCallback, useSyncExternalStore } from 'react';
|
|
2
|
+
import { ClientContext, StoreContext } from '../context.js';
|
|
3
|
+
const EMPTY = { messages: [], loading: true, error: null };
|
|
4
|
+
export function useMessages(channel) {
|
|
5
|
+
const ctx = useContext(ClientContext);
|
|
6
|
+
const store = useContext(StoreContext);
|
|
7
|
+
if (!ctx || !store)
|
|
8
|
+
throw new Error('useMessages must be used within <RelayProvider>');
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
store.updateChannelMessages(channel, (prev) => ({ ...prev, loading: true }));
|
|
11
|
+
ctx.agent.messages(channel, { limit: 50 })
|
|
12
|
+
.then((messages) => {
|
|
13
|
+
store.updateChannelMessages(channel, () => ({ messages, loading: false, error: null }));
|
|
14
|
+
})
|
|
15
|
+
.catch((error) => {
|
|
16
|
+
store.updateChannelMessages(channel, (prev) => ({
|
|
17
|
+
...prev,
|
|
18
|
+
loading: false,
|
|
19
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
20
|
+
}));
|
|
21
|
+
});
|
|
22
|
+
ctx.ws.subscribe([channel]);
|
|
23
|
+
return () => {
|
|
24
|
+
ctx.ws.unsubscribe([channel]);
|
|
25
|
+
};
|
|
26
|
+
}, [channel, ctx.agent, ctx.ws, store]);
|
|
27
|
+
const data = useSyncExternalStore(store.subscribe, () => store.getState().channelMessages[channel] ?? EMPTY);
|
|
28
|
+
const fetchMore = useCallback(async () => {
|
|
29
|
+
const current = store.getState().channelMessages[channel];
|
|
30
|
+
if (!current || current.messages.length === 0)
|
|
31
|
+
return;
|
|
32
|
+
const oldest = current.messages[0];
|
|
33
|
+
const older = await ctx.agent.messages(channel, { before: oldest.id, limit: 50 });
|
|
34
|
+
store.updateChannelMessages(channel, (prev) => ({
|
|
35
|
+
...prev,
|
|
36
|
+
messages: [...older, ...prev.messages],
|
|
37
|
+
}));
|
|
38
|
+
}, [channel, ctx.agent, store]);
|
|
39
|
+
return {
|
|
40
|
+
messages: data.messages,
|
|
41
|
+
loading: data.loading,
|
|
42
|
+
error: data.error,
|
|
43
|
+
fetchMore,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=useMessages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMessages.js","sourceRoot":"","sources":["../../src/hooks/useMessages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AACjF,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAG5D,MAAM,KAAK,GAAoB,EAAE,QAAQ,EAAE,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAE5E,MAAM,UAAU,WAAW,CAAC,OAAe;IACzC,MAAM,GAAG,GAAG,UAAU,CAAC,aAAa,CAAC,CAAC;IACtC,MAAM,KAAK,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;IACvC,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IAEvF,SAAS,CAAC,GAAG,EAAE;QACb,KAAK,CAAC,qBAAqB,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QAE7E,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;aACvC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE;YACjB,KAAK,CAAC,qBAAqB,CAAC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nC,MAAM,KAAK,GAAG,MAAM,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC;QAClF,KAAK,CAAC,qBAAqB,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YAC9C,GAAG,IAAI;YACP,QAAQ,EAAE,CAAC,GAAG,KAAK,EAAE,GAAG,IAAI,CAAC,QAAQ,CAAC;SACvC,CAAC,CAAC,CAAC;IACN,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;IAEhC,OAAO;QACL,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,SAAS;KACV,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePresence.d.ts","sourceRoot":"","sources":["../../src/hooks/usePresence.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD,wBAAgB,WAAW,IAAI,iBAAiB,CAiC/C"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { useContext, useEffect, useSyncExternalStore } from 'react';
|
|
2
|
+
import { ClientContext, StoreContext } from '../context.js';
|
|
3
|
+
export function usePresence() {
|
|
4
|
+
const ctx = useContext(ClientContext);
|
|
5
|
+
const store = useContext(StoreContext);
|
|
6
|
+
if (!ctx || !store)
|
|
7
|
+
throw new Error('usePresence must be used within <RelayProvider>');
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
store.setState({ agents: { ...store.getState().agents, loading: true } });
|
|
10
|
+
ctx.relay.agents.list()
|
|
11
|
+
.then((data) => {
|
|
12
|
+
store.setState({ agents: { data, loading: false, error: null } });
|
|
13
|
+
})
|
|
14
|
+
.catch((error) => {
|
|
15
|
+
store.setState({
|
|
16
|
+
agents: {
|
|
17
|
+
...store.getState().agents,
|
|
18
|
+
loading: false,
|
|
19
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
}, [ctx.relay, store]);
|
|
24
|
+
const state = useSyncExternalStore(store.subscribe, () => store.getState().agents);
|
|
25
|
+
return {
|
|
26
|
+
agents: state.data,
|
|
27
|
+
loading: state.loading,
|
|
28
|
+
error: state.error,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=usePresence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePresence.js","sourceRoot":"","sources":["../../src/hooks/usePresence.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAG5D,MAAM,UAAU,WAAW;IACzB,MAAM,GAAG,GAAG,UAAU,CAAC,aAAa,CAAC,CAAC;IACtC,MAAM,KAAK,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;IACvC,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IAEvF,SAAS,CAAC,GAAG,EAAE;QACb,KAAK,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,EAAE,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;QAE1E,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE;aACpB,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;YACb,KAAK,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;QACpE,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;YACxB,KAAK,CAAC,QAAQ,CAAC;gBACb,MAAM,EAAE;oBACN,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC,MAAM;oBAC1B,OAAO,EAAE,KAAK;oBACd,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;iBACjE;aACF,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACP,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;IAEvB,MAAM,KAAK,GAAG,oBAAoB,CAChC,KAAK,CAAC,SAAS,EACf,GAAG,EAAE,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,MAAM,CAC9B,CAAC;IAEF,OAAO;QACL,MAAM,EAAE,KAAK,CAAC,IAAI;QAClB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,KAAK,EAAE,KAAK,CAAC,KAAK;KACnB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useReaction.d.ts","sourceRoot":"","sources":["../../src/hooks/useReaction.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD,wBAAgB,WAAW,IAAI,iBAAiB,CAa/C"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useContext, useCallback } from 'react';
|
|
2
|
+
import { ClientContext } from '../context.js';
|
|
3
|
+
export function useReaction() {
|
|
4
|
+
const ctx = useContext(ClientContext);
|
|
5
|
+
if (!ctx)
|
|
6
|
+
throw new Error('useReaction must be used within <RelayProvider>');
|
|
7
|
+
const react = useCallback(async (messageId, emoji) => {
|
|
8
|
+
await ctx.agent.react(messageId, emoji);
|
|
9
|
+
}, [ctx.agent]);
|
|
10
|
+
const unreact = useCallback(async (messageId, emoji) => {
|
|
11
|
+
await ctx.agent.unreact(messageId, emoji);
|
|
12
|
+
}, [ctx.agent]);
|
|
13
|
+
return { react, unreact };
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=useReaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useReaction.js","sourceRoot":"","sources":["../../src/hooks/useReaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAG9C,MAAM,UAAU,WAAW;IACzB,MAAM,GAAG,GAAG,UAAU,CAAC,aAAa,CAAC,CAAC;IACtC,IAAI,CAAC,GAAG;QAAE,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IAE7E,MAAM,KAAK,GAAG,WAAW,CAAC,KAAK,EAAE,SAAiB,EAAE,KAAa,EAAiB,EAAE;QAClF,MAAM,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IAC1C,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;IAEhB,MAAM,OAAO,GAAG,WAAW,CAAC,KAAK,EAAE,SAAiB,EAAE,KAAa,EAAiB,EAAE;QACpF,MAAM,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IAC5C,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;IAEhB,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRelay.d.ts","sourceRoot":"","sources":["../../src/hooks/useRelay.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAG5C,wBAAgB,QAAQ,IAAI,KAAK,CAIhC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { useContext } from 'react';
|
|
2
|
+
import { ClientContext } from '../context.js';
|
|
3
|
+
export function useRelay() {
|
|
4
|
+
const ctx = useContext(ClientContext);
|
|
5
|
+
if (!ctx)
|
|
6
|
+
throw new Error('useRelay must be used within <RelayProvider>');
|
|
7
|
+
return ctx.relay;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=useRelay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRelay.js","sourceRoot":"","sources":["../../src/hooks/useRelay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAEnC,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,MAAM,UAAU,QAAQ;IACtB,MAAM,GAAG,GAAG,UAAU,CAAC,aAAa,CAAC,CAAC;IACtC,IAAI,CAAC,GAAG;QAAE,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IAC1E,OAAO,GAAG,CAAC,KAAK,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useReply.d.ts","sourceRoot":"","sources":["../../src/hooks/useReply.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,wBAAgB,QAAQ,IAAI,cAAc,CA0BzC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useContext, useState, useCallback } from 'react';
|
|
2
|
+
import { ClientContext, StoreContext } from '../context.js';
|
|
3
|
+
export function useReply() {
|
|
4
|
+
const ctx = useContext(ClientContext);
|
|
5
|
+
const store = useContext(StoreContext);
|
|
6
|
+
if (!ctx || !store)
|
|
7
|
+
throw new Error('useReply must be used within <RelayProvider>');
|
|
8
|
+
const [sending, setSending] = useState(false);
|
|
9
|
+
const reply = useCallback(async (messageId, text) => {
|
|
10
|
+
setSending(true);
|
|
11
|
+
try {
|
|
12
|
+
const msg = await ctx.agent.reply(messageId, text);
|
|
13
|
+
// Optimistic: append reply to thread (deduplicated when WS event arrives)
|
|
14
|
+
store.updateThread(messageId, (prev) => {
|
|
15
|
+
if (prev.replies.some((r) => r.id === msg.id))
|
|
16
|
+
return prev;
|
|
17
|
+
return { ...prev, replies: [...prev.replies, msg] };
|
|
18
|
+
});
|
|
19
|
+
return msg;
|
|
20
|
+
}
|
|
21
|
+
finally {
|
|
22
|
+
setSending(false);
|
|
23
|
+
}
|
|
24
|
+
}, [ctx.agent, store]);
|
|
25
|
+
return { reply, sending };
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=useReply.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useReply.js","sourceRoot":"","sources":["../../src/hooks/useReply.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAI5D,MAAM,UAAU,QAAQ;IACtB,MAAM,GAAG,GAAG,UAAU,CAAC,aAAa,CAAC,CAAC;IACtC,MAAM,KAAK,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;IACvC,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IAEpF,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAE9C,MAAM,KAAK,GAAG,WAAW,CAAC,KAAK,EAC7B,SAAiB,EACjB,IAAY,EACc,EAAE;QAC5B,UAAU,CAAC,IAAI,CAAC,CAAC;QACjB,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;YACnD,0EAA0E;YAC1E,KAAK,CAAC,YAAY,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,EAAE;gBACrC,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,GAAG,CAAC,EAAE,CAAC;oBAAE,OAAO,IAAI,CAAC;gBAC3D,OAAO,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,EAAE,CAAC;YACtD,CAAC,CAAC,CAAC;YACH,OAAO,GAAG,CAAC;QACb,CAAC;gBAAS,CAAC;YACT,UAAU,CAAC,KAAK,CAAC,CAAC;QACpB,CAAC;IACH,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;IAEvB,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { UseSearchReturn } from '../types.js';
|
|
2
|
+
export interface UseSearchOptions {
|
|
3
|
+
channel?: string;
|
|
4
|
+
from?: string;
|
|
5
|
+
limit?: number;
|
|
6
|
+
}
|
|
7
|
+
export declare function useSearch(query: string, opts?: UseSearchOptions): UseSearchReturn;
|
|
8
|
+
//# sourceMappingURL=useSearch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSearch.d.ts","sourceRoot":"","sources":["../../src/hooks/useSearch.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,gBAAgB,GAAG,eAAe,CAkCjF"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useState, useEffect, useContext, useRef } from 'react';
|
|
2
|
+
import { ClientContext } from '../context.js';
|
|
3
|
+
export function useSearch(query, opts) {
|
|
4
|
+
const ctx = useContext(ClientContext);
|
|
5
|
+
if (!ctx)
|
|
6
|
+
throw new Error('useSearch must be used within <RelayProvider>');
|
|
7
|
+
const [results, setResults] = useState([]);
|
|
8
|
+
const [loading, setLoading] = useState(false);
|
|
9
|
+
const [error, setError] = useState(null);
|
|
10
|
+
const optsRef = useRef(opts);
|
|
11
|
+
optsRef.current = opts;
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (!query || query.length < 2) {
|
|
14
|
+
setResults([]);
|
|
15
|
+
setLoading(false);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
setLoading(true);
|
|
19
|
+
const timer = setTimeout(async () => {
|
|
20
|
+
try {
|
|
21
|
+
const data = await ctx.agent.search(query, optsRef.current);
|
|
22
|
+
setResults(data);
|
|
23
|
+
setError(null);
|
|
24
|
+
}
|
|
25
|
+
catch (e) {
|
|
26
|
+
setError(e instanceof Error ? e : new Error(String(e)));
|
|
27
|
+
}
|
|
28
|
+
finally {
|
|
29
|
+
setLoading(false);
|
|
30
|
+
}
|
|
31
|
+
}, 300);
|
|
32
|
+
return () => clearTimeout(timer);
|
|
33
|
+
}, [query, ctx.agent]);
|
|
34
|
+
return { results, loading, error };
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=useSearch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSearch.js","sourceRoot":"","sources":["../../src/hooks/useSearch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,M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,CAAC;gBACT,UAAU,CAAC,KAAK,CAAC,CAAC;YACpB,CAAC;QACH,CAAC,EAAE,GAAG,CAAC,CAAC;QAER,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;IAEvB,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSendDM.d.ts","sourceRoot":"","sources":["../../src/hooks/useSendDM.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,wBAAgB,SAAS,IAAI,eAAe,CAgB3C"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useContext, useState, useCallback } from 'react';
|
|
2
|
+
import { ClientContext } from '../context.js';
|
|
3
|
+
export function useSendDM() {
|
|
4
|
+
const ctx = useContext(ClientContext);
|
|
5
|
+
if (!ctx)
|
|
6
|
+
throw new Error('useSendDM must be used within <RelayProvider>');
|
|
7
|
+
const [sending, setSending] = useState(false);
|
|
8
|
+
const send = useCallback(async (agent, text) => {
|
|
9
|
+
setSending(true);
|
|
10
|
+
try {
|
|
11
|
+
await ctx.agent.dm(agent, text);
|
|
12
|
+
}
|
|
13
|
+
finally {
|
|
14
|
+
setSending(false);
|
|
15
|
+
}
|
|
16
|
+
}, [ctx.agent]);
|
|
17
|
+
return { send, sending };
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=useSendDM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSendDM.js","sourceRoot":"","sources":["../../src/hooks/useSendDM.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAG9C,MAAM,UAAU,SAAS;IACvB,MAAM,GAAG,GAAG,UAAU,CAAC,aAAa,CAAC,CAAC;IACtC,IAAI,CAAC,GAAG;QAAE,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;IAE3E,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAE9C,MAAM,IAAI,GAAG,WAAW,CAAC,KAAK,EAAE,KAAa,EAAE,IAAY,EAAiB,EAAE;QAC5E,UAAU,CAAC,IAAI,CAAC,CAAC;QACjB,IAAI,CAAC;YACH,MAAM,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QAClC,CAAC;gBAAS,CAAC;YACT,UAAU,CAAC,KAAK,CAAC,CAAC;QACpB,CAAC;IACH,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;IAEhB,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSendMessage.d.ts","sourceRoot":"","sources":["../../src/hooks/useSendMessage.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAExD,wBAAgB,cAAc,IAAI,oBAAoB,CA2BrD"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useContext, useState, useCallback } from 'react';
|
|
2
|
+
import { ClientContext, StoreContext } from '../context.js';
|
|
3
|
+
export function useSendMessage() {
|
|
4
|
+
const ctx = useContext(ClientContext);
|
|
5
|
+
const store = useContext(StoreContext);
|
|
6
|
+
if (!ctx || !store)
|
|
7
|
+
throw new Error('useSendMessage must be used within <RelayProvider>');
|
|
8
|
+
const [sending, setSending] = useState(false);
|
|
9
|
+
const send = useCallback(async (channel, text, opts) => {
|
|
10
|
+
setSending(true);
|
|
11
|
+
try {
|
|
12
|
+
const msg = await ctx.agent.send(channel, text, opts);
|
|
13
|
+
// Optimistic: append to local state (deduplicated when WS event arrives)
|
|
14
|
+
store.updateChannelMessages(channel, (prev) => {
|
|
15
|
+
if (prev.messages.some((m) => m.id === msg.id))
|
|
16
|
+
return prev;
|
|
17
|
+
return { ...prev, messages: [...prev.messages, msg] };
|
|
18
|
+
});
|
|
19
|
+
return msg;
|
|
20
|
+
}
|
|
21
|
+
finally {
|
|
22
|
+
setSending(false);
|
|
23
|
+
}
|
|
24
|
+
}, [ctx.agent, store]);
|
|
25
|
+
return { send, sending };
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=useSendMessage.js.map
|