bun+fixes
This commit is contained in:
parent
5d749c09a7
commit
4650469247
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -14,3 +14,4 @@ src/graphql/introspec.gen.ts
|
||||||
stats.html
|
stats.html
|
||||||
*.scss.d.ts
|
*.scss.d.ts
|
||||||
pnpm-lock.yaml
|
pnpm-lock.yaml
|
||||||
|
bun.lockb
|
13419
package-lock.json
generated
13419
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
|
@ -28,16 +28,15 @@ export const InboxProvider = (props: { children: JSX.Element }) => {
|
||||||
const [chats, setChats] = createSignal<Chat[]>([])
|
const [chats, setChats] = createSignal<Chat[]>([])
|
||||||
const [messages, setMessages] = createSignal<Message[]>([])
|
const [messages, setMessages] = createSignal<Message[]>([])
|
||||||
|
|
||||||
fetchEventSource('https://chat.discours.io/connect', {
|
fetchEventSource('https://connect.discours.io', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Authorization': getToken()
|
Authorization: getToken()
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
foo: 'bar'
|
foo: 'bar'
|
||||||
}),
|
}),
|
||||||
// signal: signal, TODO: sometimes need to call /disconnect
|
|
||||||
onmessage(event) {
|
onmessage(event) {
|
||||||
const message = JSON.parse(event.data)
|
const message = JSON.parse(event.data)
|
||||||
|
|
||||||
|
@ -47,14 +46,17 @@ export const InboxProvider = (props: { children: JSX.Element }) => {
|
||||||
},
|
},
|
||||||
onclose() {
|
onclose() {
|
||||||
// if no error thrown - it will reconnect
|
// if no error thrown - it will reconnect
|
||||||
console.log("sse connection closed")
|
console.log('sse connection closed by server')
|
||||||
},
|
},
|
||||||
onerror(err) {
|
onerror(err) {
|
||||||
console.warn(err)
|
console.warn(err)
|
||||||
|
console.error('sse connection closed by error')
|
||||||
throw new Error() // hack to close the connection
|
throw new Error() // hack to close the connection
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// TODO: maybe sometimes need to call /disconnect
|
||||||
|
|
||||||
const loadChats = async () => {
|
const loadChats = async () => {
|
||||||
try {
|
try {
|
||||||
const newChats = await inboxClient.getChats({ limit: 50, offset: 0 })
|
const newChats = await inboxClient.getChats({ limit: 50, offset: 0 })
|
||||||
|
@ -101,7 +103,6 @@ export const InboxProvider = (props: { children: JSX.Element }) => {
|
||||||
loadChats,
|
loadChats,
|
||||||
getMessages,
|
getMessages,
|
||||||
sendMessage
|
sendMessage
|
||||||
// unsubscribe // TODO: call unsubscribe some time!
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const value: InboxContextType = { chats, messages, actions }
|
const value: InboxContextType = { chats, messages, actions }
|
||||||
|
|
Loading…
Reference in New Issue
Block a user