|
@@ -1,5 +1,8 @@
|
|
|
-import React, { useCallback, useState } from 'react';
|
|
|
|
|
|
|
+import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
|
import { CircleLoader } from 'react-spinners';
|
|
import { CircleLoader } from 'react-spinners';
|
|
|
|
|
+import { useCTA } from '../hooks/cta';
|
|
|
|
|
+
|
|
|
|
|
+import * as Styled from './identify.styles';
|
|
|
|
|
|
|
|
export type Props = {
|
|
export type Props = {
|
|
|
connecting: boolean;
|
|
connecting: boolean;
|
|
@@ -16,16 +19,36 @@ export const Identify: React.FC<Props> = ({ connecting, onIdentify }) => {
|
|
|
onIdentify(name);
|
|
onIdentify(name);
|
|
|
}, [name, onIdentify]);
|
|
}, [name, onIdentify]);
|
|
|
|
|
|
|
|
|
|
+ const input = useRef<HTMLInputElement>(null);
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
|
+ setImmediate(() => {
|
|
|
|
|
+ input.current?.focus();
|
|
|
|
|
+ });
|
|
|
|
|
+ }, []);
|
|
|
|
|
+
|
|
|
|
|
+ const inputOnKeydown = useCallback(
|
|
|
|
|
+ (event: React.KeyboardEvent<HTMLInputElement>) => {
|
|
|
|
|
+ if (event.key === 'Enter') {
|
|
|
|
|
+ onConnect();
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ [onConnect],
|
|
|
|
|
+ );
|
|
|
|
|
+ const buttonHandlers = useCTA(onConnect);
|
|
|
|
|
+
|
|
|
return (
|
|
return (
|
|
|
- <div>
|
|
|
|
|
- <div>
|
|
|
|
|
- <span>Set client name:</span>
|
|
|
|
|
- <input type="text" onChange={onChange} />
|
|
|
|
|
- <button onClick={onConnect} disabled={connecting}>
|
|
|
|
|
|
|
+ <Styled.Container>
|
|
|
|
|
+ <Styled.Title>go-music-player</Styled.Title>
|
|
|
|
|
+ <Styled.Instruction>Set client name:</Styled.Instruction>
|
|
|
|
|
+ <Styled.InputGroup>
|
|
|
|
|
+ <input ref={input} type="text" onChange={onChange} onKeyDown={inputOnKeydown} />
|
|
|
|
|
+ <button disabled={connecting} {...buttonHandlers}>
|
|
|
Connect
|
|
Connect
|
|
|
</button>
|
|
</button>
|
|
|
- {connecting && <CircleLoader size={50} />}
|
|
|
|
|
- </div>
|
|
|
|
|
- </div>
|
|
|
|
|
|
|
+ </Styled.InputGroup>
|
|
|
|
|
+ <Styled.Loader visible={connecting}>
|
|
|
|
|
+ <CircleLoader size={50} color="white" />
|
|
|
|
|
+ </Styled.Loader>
|
|
|
|
|
+ </Styled.Container>
|
|
|
);
|
|
);
|
|
|
};
|
|
};
|