npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

chat-frontend-library

v1.0.145

Published

``` npm install chat-frontend-library --save ```

Downloads

3,221

Readme

Install

npm install chat-frontend-library --save

Usage

Create Redux store:

import { configureStore } from '@reduxjs/toolkit';
import { chatApi, chatAppSlice, commonApi } from 'chat-frontend-library';

 const store = configureStore({
  reducer: {
    [commonApi.reducerPath]: commonApi.reducer,
    [chatApi.reducerPath]: chatApi.reducer,
    [chatAppSlice.name]: chatAppSlice.reducer,
    ...
    //Add your reducers if necessary
  },
  middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(commonApi.middleware, chatApi.middleware, ...),
});
export default store;

Wrap your root component file in a Provider:

import store from './store';
import { Provider } from "react-redux";

 <Provider store={store}>
   <App />
 </Provider>

Imports

Import the components and constants from the package into the file:

import { Chat, ChatList, LS_TOKEN_KEY, LS_USER_ID } from "chat-frontend-library";

Important

After logging the user into your application, you should set the access token in the local storage of the browser for the chat components:

localStorage.setItem(LS_TOKEN_KEY, access_token);

After calling the function to refresh a token from your app, the new received token must be installed in local storage of the browser under the key LS_TOKEN_KEY and returned from the function.


Chat Component

import { Chat } from "chat-frontend-library";

  <Chat
    opponent_id="opponent_id"
    user_id="user_id"
    user_locale="locale"
    isOnlyChat={true}
    cbHandleCloseChat={cbCloseChat}
    handleRefreshToken={cbRefreshToken}
    classHeader="customCSSClass"
    classMessages="customCSSClass"
  />
Chat props

| prop | default | type | description | | :----------------- | :------ | :------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------ | | opponent_id | none | string | User opponent ID | | user_id | none | string | User id got from the access token by decoding | | user_locale | ru/en | string | Chat interface language. The browser language is set by default | | isOnlyChat | none | boolean | true value is set when only the chat close functionality is used. false allows more chat functionality | | cbHandleCloseChat | none | function | A callback function that is called when the user clicks the close chat button | | handleRefreshToken | none | function | An asynchronous callback function that is called if the chat API call returns an error. Takes an axios error as an argument. Should return the new user token | | classHeader | " " | string | Adds a custom style class for the Chat header | | classMessages | " " | string | Adds a custom style class for the box with messages |


ChatList Component

import { ChatList } from "chat-frontend-library";

  <ChatList
    user_id="user_id"
    user_locale="locale"
    isOnlyChatList={true}
    cbHandleCloseChatList={handleCloseList}
    handleRefreshToken={handleRefreshToken}
    classList="customCSSClass"
    cbHandleOpenChat={handleOpenChat}
  />
ChatList props

| prop | default | type | description | | :-------------------- | :------ | :------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | user_id | none | string | User id got from the access token by decoding | | user_locale | ru/en | string | ChatList interface language. The browser language is set by default. | | isOnlyChatList | none | boolean | true value is set when only the chat list close functionality is used. false allows more chat list functionality. | | cbHandleCloseChatList | none | function | A callback function that is called when the user clicks the close chat button. | | cbHandleOpenChat | none | function | A callback function that is called when the user clicks on a specific chat in the list. Takes an object as a function argument: {chat_id:string; opponent_id:string} | | handleRefreshToken | none | function | An asynchronous callback function that is called if the chat API call returns an error. Takes an axios error as an argument. Should return the new user token. | | classList | " " | string | Adds a custom style class for the ChatList wrapper |