Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[arcade-chat] Basic chat channels+messages flow works #28

Merged
merged 31 commits into from
Aug 3, 2022
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
992eca5
before axe ws tests
AtlantisPleb Aug 2, 2022
61b2950
axe that for now
AtlantisPleb Aug 2, 2022
0d54440
Axe server ws
AtlantisPleb Aug 2, 2022
f374271
Add use-arcade store
AtlantisPleb Aug 2, 2022
cdc27a2
Initial subscribe
AtlantisPleb Aug 2, 2022
5478178
Fix type of useRideRequests
AtlantisPleb Aug 2, 2022
e7f8cb0
useRideRequests() working
AtlantisPleb Aug 2, 2022
bca8dd6
Try pull in UI, eh
AtlantisPleb Aug 2, 2022
2eabedf
Rename nostr-client to arcade-chat
AtlantisPleb Aug 2, 2022
eeee29a
replace microbundle w tsup
AtlantisPleb Aug 2, 2022
643860f
Button to create demo chatroom
AtlantisPleb Aug 2, 2022
a479a35
createDemoChannel good except needs random
AtlantisPleb Aug 2, 2022
0ab05ed
Creating demo channel event (not yet sending)
AtlantisPleb Aug 2, 2022
d326f3a
Fix kind
AtlantisPleb Aug 2, 2022
4a0a8e6
Storing/retrieving event 40s
AtlantisPleb Aug 2, 2022
5760360
Initial ChannelList with channel type
AtlantisPleb Aug 2, 2022
82da6b5
use NostrKind
AtlantisPleb Aug 2, 2022
96e22b9
ChannelList
AtlantisPleb Aug 2, 2022
0895fa9
Set up ChannelPreview and navto
AtlantisPleb Aug 2, 2022
445470c
Pull over tabbar and nav stuff
AtlantisPleb Aug 2, 2022
306846a
Fix UI depending on RN 0.69.1
AtlantisPleb Aug 2, 2022
9fb50be
Basic ChannelPreview/ChannelNav
AtlantisPleb Aug 2, 2022
0ab0d18
grab channel id param and axe require cycle
AtlantisPleb Aug 2, 2022
c7202ed
switch up tab icons
AtlantisPleb Aug 2, 2022
772d1d5
Initial ChannelScreen/Message placeholders
AtlantisPleb Aug 3, 2022
8a66bd5
MessageInput UI
AtlantisPleb Aug 3, 2022
b8e9f90
Navbutton back for Channel
AtlantisPleb Aug 3, 2022
18ee69d
MessageInput ready to send
AtlantisPleb Aug 3, 2022
70355a7
Send first message
AtlantisPleb Aug 3, 2022
575a72e
useChannelMessages works
AtlantisPleb Aug 3, 2022
8299908
Basic chat flow works
AtlantisPleb Aug 3, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Initial subscribe
AtlantisPleb committed Aug 2, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit cdc27a24b7e7432ae198337cc49730699ded1d1c
9 changes: 8 additions & 1 deletion apps/nostr-client/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { StatusBar } from 'expo-status-bar'
import { useEffect } from 'react'
import { SafeAreaProvider } from 'react-native-safe-area-context'
import { useArcadeRelay } from '@arcadecity/use-arcade'
import useCachedResources from './hooks/useCachedResources'
@@ -8,7 +9,13 @@ import Navigation from './navigation'
export const App = () => {
const isLoadingComplete = useCachedResources()
const colorScheme = useColorScheme()
useArcadeRelay()
const [state, actions] = useArcadeRelay()

useEffect(() => {
if (state.ready) {
actions.initialSubscribe()
}
}, [state.ready])

if (!isLoadingComplete) {
return null
27 changes: 23 additions & 4 deletions packages/use-arcade/src/hooks/useArcadeRelay.ts
Original file line number Diff line number Diff line change
@@ -3,22 +3,31 @@ import { SetStateAction, useEffect, useRef, useState } from 'react'

export type UseArcadeRelayState = {
isPaused: boolean
ready: boolean
}

export type UseArcadeRelayActions = {
initialSubscribe: () => void
setPause: React.Dispatch<SetStateAction<boolean>>
}

type UseArcadeRelayFunction = () => [UseArcadeRelayState, UseArcadeRelayActions]

export const useArcadeRelay: UseArcadeRelayFunction = () => {
const [isPaused, setPause] = useState<boolean>(false)
const [ready, setReady] = useState<boolean>(false)
const ws = useRef<WebSocket | null>(null)

useEffect(() => {
ws.current = new WebSocket('wss://relay.arcade.city')
ws.current.onopen = () => console.log('ws opened')
ws.current.onclose = () => console.log('ws closed')
ws.current.onopen = () => {
console.log('ws opened')
setReady(true)
}
ws.current.onclose = () => {
console.log('ws closed')
setReady(false)
}

const wsCurrent = ws.current

@@ -37,8 +46,18 @@ export const useArcadeRelay: UseArcadeRelayFunction = () => {
}
}, [isPaused])

const state: UseArcadeRelayState = { isPaused }
const actions: UseArcadeRelayActions = { setPause }
const initialSubscribe = () => {
if (!ws.current) return
if (ws.current.readyState !== WebSocket.OPEN) {
console.log('Not ready.')
setReady(false)
return
}
ws.current.send(JSON.stringify(['REQ', Math.random().toString().slice(2), { kind: 60 }]))
}

const state: UseArcadeRelayState = { isPaused, ready }
const actions: UseArcadeRelayActions = { initialSubscribe, setPause }

return [state, actions]
}