feat: direct client to first fave

This commit is contained in:
cha0s 2020-07-25 09:08:29 -05:00
parent 81ad40520a
commit 7fb8026e28

View File

@ -5,15 +5,21 @@ import React, {useEffect} from 'react';
import {useDispatch, useSelector} from 'react-redux'; import {useDispatch, useSelector} from 'react-redux';
import {Link} from 'react-router-dom'; import {Link} from 'react-router-dom';
import {userSelector} from '~/common/state/user'; import {favoriteChannelsSelector, userSelector} from '~/common/state/user';
export default function Home() { export default function Home() {
const dispatch = useDispatch(); const dispatch = useDispatch();
const favorites = useSelector(favoriteChannelsSelector);
const user = useSelector(userSelector); const user = useSelector(userSelector);
useEffect(() => { useEffect(() => {
if (user.id) { let path;
dispatch(replace('/chat')); if (favorites.length > 0) {
path = `/chat/r/${favorites[0]}`;
} }
else if (user.id) {
path = '/chat';
}
dispatch(replace(path));
}); });
return ( return (
<div className="home"> <div className="home">