This repository has been archived on 2023-11-14. You can view files and clone it, but cannot push or open issues/pull-requests.
viscord/packages/renderer/src/pages/Channels.tsx

51 lines
1.0 KiB
TypeScript
Raw Normal View History

2022-07-21 23:45:52 -04:00
import { useEffect, useState } from 'react';
import { registerRouter, router, send, unregisterRouter } from '../lib/api';
function useRouter(actions: Function | object, deps: any[]) {
const _router = typeof actions === 'object' ? router(actions) : actions;
useEffect(() => {
registerRouter(_router);
return () => {
unregisterRouter(_router);
};
}, deps);
return {
send: send,
};
}
interface IChannel {
uid: string;
name: string;
}
export default function Channels() {
const [channels, setChannels] = useState<IChannel[]>([]);
const { send } = useRouter({
'channels:list'(data: any) {
// console.log(data)
setChannels(data);
},
}, [channels]);
useEffect(() => {
if(channels.length === 0) {
send('channels:list');
}
}, [channels]);
return (
<>
{channels.map(channel => (
<div key={channel.uid}>
<span style={{
fontWeight: 'bold',
}}>#</span>{channel.name}
</div>
))}
</>
);
}