Skip to content

Commit

Permalink
refactor: Chat to use Typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
yevhenorlov committed Oct 23, 2019
1 parent f63e4cf commit de80422
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const Messages = styled.div`
flex: 1;
`;

export const Chat = () => {
export const Chat: React.FC = () => {
const [value, setValue] = useState('');
const [height, setHeight] = useState('');
const { state, actions } = useOvermind();
Expand All @@ -34,7 +34,7 @@ export const Chat = () => {
}
useEffect(scrollDown);

const handleKeyDown = e => {
const handleKeyDown = (e: KeyboardEvent) => {
if (e.keyCode === ENTER && !e.shiftKey) {
e.preventDefault();
e.stopPropagation();
Expand All @@ -47,7 +47,7 @@ export const Chat = () => {
}
};

const handleChange = e => {
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setValue(e.target.value);
};

Expand Down
5 changes: 4 additions & 1 deletion packages/common/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ export type LiveUser = {
avatarUrl: string;
};

export type ChatUserGetter = (id: string) => string;

export type RoomInfo = {
startTime: number;
ownerIds: string[];
Expand All @@ -211,7 +213,8 @@ export type RoomInfo = {
// We keep a separate map of user_id -> username for the case when
// a user disconnects. We still need to keep track of the name.
users: {
[id: string]: string;
[id: string]: string | ChatUserGetter;
get: ChatUserGetter;
};
};
};
Expand Down

0 comments on commit de80422

Please sign in to comment.