bun+fixes

This commit is contained in:
Untone 2023-10-11 20:03:20 +03:00
parent 5d749c09a7
commit 4650469247
3 changed files with 18 additions and 13419 deletions

1
.gitignore vendored
View File

@ -14,3 +14,4 @@ src/graphql/introspec.gen.ts
stats.html
*.scss.d.ts
pnpm-lock.yaml
bun.lockb

13419
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -28,33 +28,35 @@ export const InboxProvider = (props: { children: JSX.Element }) => {
const [chats, setChats] = createSignal<Chat[]>([])
const [messages, setMessages] = createSignal<Message[]>([])
fetchEventSource('https://chat.discours.io/connect', {
fetchEventSource('https://connect.discours.io', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': getToken()
'Content-Type': 'application/json',
Authorization: getToken()
},
body: JSON.stringify({
foo: 'bar'
foo: 'bar'
}),
// signal: signal, TODO: sometimes need to call /disconnect
onmessage(event) {
const message = JSON.parse(event.data)
// TODO: Do something with the message
console.log(message)
},
onclose() {
// if no error thrown - it will reconnect
console.log("sse connection closed")
console.log('sse connection closed by server')
},
onerror(err) {
console.warn(err)
console.error('sse connection closed by error')
throw new Error() // hack to close the connection
}
})
// TODO: maybe sometimes need to call /disconnect
const loadChats = async () => {
try {
const newChats = await inboxClient.getChats({ limit: 50, offset: 0 })
@ -101,7 +103,6 @@ export const InboxProvider = (props: { children: JSX.Element }) => {
loadChats,
getMessages,
sendMessage
// unsubscribe // TODO: call unsubscribe some time!
}
const value: InboxContextType = { chats, messages, actions }