semantic-ui-react#IconGroup JavaScript Examples

The following examples show how to use semantic-ui-react#IconGroup. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChatProfile.js    From react-chat-app with MIT License 4 votes vote down vote up
ChatProfile = (props) => {
  const { userObject, convertedName } = useAuth();
  const [avatarURL, setAvatarURL] = useState();
  const [userStatus, setUserStatus] = useState();
  const inputRef = useRef(null);
  const [image, setImage] = useState();
  const [avatarState, setAvatarState] = useState(false);
  const [statusState, setStatusState] = useState(false);
  const [avatarVisibility, setAvatarVisibility] = useState(true);
  const { conn } = useContext(ChatEngineContext)

  const capitalize = (str, lower = true) => {
    return (lower ? str.toLowerCase() : str).replace(
      /(?:^|\s|["'([{])+\S/g,
      (match) => match.toUpperCase()
    );
  };

  const onFileAttach = (file) => {
    setImage(file);
  };

  const updateAv = () => {
    const myHeaders = new Headers();
    myHeaders.append("Project-ID", process.env.REACT_APP_PROJECT_ID);
    myHeaders.append("User-Name", convertedName);
    myHeaders.append("User-Secret", userObject.uid);

    const formdata = new FormData();
    formdata.append("avatar", image, image.name);

    const requestOptions = {
      method: "PATCH",
      headers: myHeaders,
      body: formdata,
      redirect: "follow",
    };

    fetch("https://api.chatengine.io/users/me/", requestOptions)
      .then(() => {
        setAvatarState(false)
        setAvatarURL()
      }
      )
  };

  useEffect(() => {
    var myHeaders = new Headers();
    myHeaders.append("Project-ID", process.env.REACT_APP_PROJECT_ID);
    myHeaders.append("User-Name", props.conn.userName);
    myHeaders.append("User-Secret", props.conn.userSecret);

    var requestOptions = {
      method: "GET",
      headers: myHeaders,
      redirect: "follow",
    };

    fetch("https://api.chatengine.io/users/me/", requestOptions)
      .then((response) => response.json())
      .then((result) => {
        setUserStatus(result.first_name)
        setAvatarURL(result.avatar);
        setAvatarState(true);
        setStatusState(true)

      });
  }, [avatarState]);

  return (
    <div className="chat-profile-container">
      <input
        type="file"
        ref={inputRef}
        className="image-input"
        accept="image/jpeg,image/png"
        onChange={(e) => {
          const file = e.target?.files?.[0];
          if (file) {
            onFileAttach(file);
            setAvatarVisibility(false);
          }
        }}
      />

      {!!image && (
        <ChatAvatar
          crop
          file={image}
          header="Set Your Avatar"
          mode="message"
          username={props.conn.userName}
          userstatus={userStatus}
          onSubmit={(croppedImage) => {
            setImage(croppedImage);
            updateAv();
            setImage(null);
            setAvatarVisibility(true);
          }}
          close={() => {
            setImage(null)
            setAvatarVisibility(true);
          }}
        />
      )}

      {userObject.uid && avatarVisibility ? (
        <div className="current-user-info">
          <IconGroup
            onClick={() => {
              if (conn.userName === "john%20doe") {
                  alert("Changing avatar is disabled on sample account, sorry!")
                return null
                }
              const input = inputRef.current;
              if (input) {
                input.value = "";
                input.click();
              }
            }}
            className="user-avatar"
            size="large"
          >
            {avatarState ? (
              <>
                {avatarURL ? (
                  <img
                    src={avatarURL}
                    style={{ borderRadius: "50%", width: "120px" }}
                    alt=""
                  />
                ) : (
                  <img
                    src={empty}
                    style={{ borderRadius: "50%", width: "120px" }}
                    alt=""
                  />
                )}
              </>
            ) : (
              <img src={loadingAnimation} alt="" />
            )}

            <Icon corner name="camera" inverted circular />
          </IconGroup>


        </div>
      ) : (
        <div className="user-loading">
          <Loader active size="small" />
        </div>
      )}

      {!image ?
        <div className="chat-profile-info">
          <div className="current-username">
            <div className="username-border">
              {capitalize(decodeURIComponent(convertedName))}
            </div>

          </div>

          {statusState ?
            <UserStatus userStatus={userStatus} /> : ""}

        </div>
        : ""}

    </div>
  );
}
Example #2
Source File: RailHeader.jsx    From react-chatengine-demo with MIT License 4 votes vote down vote up
RailHeader = () => {
  const { chatConfig } = useChat();
  const configResolved = useResolved(chatConfig);
  const inputRef = useRef(null);
  const [image, setImage] = useState();

  const onFileAttach = file => {
    setImage(file);
  };

  return (
    <>
      <input
        type="file"
        ref={inputRef}
        className="file-input"
        accept="image/jpeg,image/png"
        onChange={e => {
          const file = e.target?.files?.[0];
          if (file) {
            onFileAttach(file);
          }
        }}
      />

      {!!image && (
        <ImageUpload
          crop
          file={image}
          header="Set Your Avatar"
          mode="message"
          onSubmit={croppedImage => {
            const storageRef = fb.storage.ref();
            const uploadRef = storageRef.child(
              `${chatConfig.userSecret}_avatar.jpg`,
            );
            uploadRef.put(croppedImage).then(() => {
              uploadRef.getDownloadURL().then(url => {
                fb.firestore
                  .collection('chatUsers')
                  .doc(chatConfig.userSecret)
                  .update({ avatar: url })
                  .then(() => {
                    setImage(null);
                  });
              });
            });
          }}
          close={() => setImage(null)}
        />
      )}

      <div className="left-rail-header">
        <Icon
          onClick={() => fb.auth.signOut()}
          className="sign-out"
          name="sign out"
        />
        {configResolved && !!chatConfig ? (
          <div className="current-user-info">
            <IconGroup
              onClick={() => {
                const input = inputRef.current;
                if (input) {
                  input.value = '';
                  input.click();
                }
              }}
              className="user-avatar"
              size="large"
            >
              {chatConfig.avatar ? (
                <Image src={chatConfig.avatar} avatar />
              ) : (
                <div className="empty-avatar">
                  {chatConfig.userName[0].toUpperCase()}
                </div>
              )}

              <Icon corner name="camera" inverted circular />
            </IconGroup>

            <div className="current-username">@{chatConfig.userName}</div>
          </div>
        ) : (
          <div className="user-loading">
            <Loader active size="small" />
          </div>
        )}
      </div>
    </>
  );
}