Skip to content

Commit

Permalink
mobile - channel creation and channel deletion fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kacper-RF committed May 18, 2023
1 parent bc28939 commit 79c3e80
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
15 changes: 11 additions & 4 deletions packages/mobile/src/screens/CreateChannel/CreateChannel.screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ import { generateChannelAddress } from '@quiet/common'
export const CreateChannelScreen: FC = () => {
const dispatch = useDispatch()

const [channel, setChannel] = useState<string>(null)
interface ChannelStructure {
channelName: string | null
channelAddress: string | null
}
const [channel, setChannel] = useState<ChannelStructure>({
channelAddress: null,
channelName: null
})
const [clearComponent, setClearComponent] = useState<boolean>(false) // How to clear component without using screen's state?

const user = useSelector(identity.selectors.currentIdentity)
Expand All @@ -35,11 +42,11 @@ export const CreateChannelScreen: FC = () => {
useEffect(() => {
if (
currentScreen === ScreenNames.CreateChannelScreen &&
channels.filter(_channel => _channel.name === channel).length > 0
channels.filter(_channel => _channel.name === channel.channelName).length > 0
) {
dispatch(
publicChannels.actions.setCurrentChannel({
channelAddress: channel
channelAddress: channel.channelAddress
})
)
setChannel(null)
Expand Down Expand Up @@ -84,7 +91,7 @@ export const CreateChannelScreen: FC = () => {
timestamp: DateTime.utc().valueOf()
}

setChannel(name)
setChannel({ channelAddress: channel.address, channelName: channel.name })

dispatch(
publicChannels.actions.createChannel({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { navigationSelectors } from '../../store/navigation/navigation.selectors
export const DeleteChannelScreen: FC<DeleteChannelScreenProps> = ({ route }) => {
const dispatch = useDispatch()

const { channel: channelRouteParam } = route.params
const { channel: channelName } = route.params

const channels = useSelector(publicChannels.selectors.publicChannels)

Expand All @@ -19,19 +19,19 @@ export const DeleteChannelScreen: FC<DeleteChannelScreenProps> = ({ route }) =>
console.log({ channels })

useEffect(() => {
if (screen === ScreenNames.DeleteChannelScreen && !channels.find(c => c.name === channelRouteParam)) {
if (screen === ScreenNames.DeleteChannelScreen && !channels.find(c => c.name === channelName)) {
dispatch(navigationActions.replaceScreen({ screen: ScreenNames.ChannelListScreen }))
}
}, [dispatch, screen, channels])

const deleteChannel = useCallback(() => {
const deletedChannel = channels.find((channel) => channel.name === channelRouteParam)
const deletedChannel = channels.find((channel) => channel.name === channelName)
dispatch(
publicChannels.actions.deleteChannel({
channelAddress: deletedChannel.address
})
)
}, [dispatch, channels, channelRouteParam])
}, [dispatch, channels, channelName])

const handleBackButton = useCallback(() => {
dispatch(
Expand All @@ -43,7 +43,7 @@ export const DeleteChannelScreen: FC<DeleteChannelScreenProps> = ({ route }) =>

return (
<DeleteChannel
name={channelRouteParam}
name={channelName}
deleteChannel={deleteChannel}
handleBackButton={handleBackButton}
/>
Expand Down

0 comments on commit 79c3e80

Please sign in to comment.