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