From e03b020397bddf35b2e2e7f521799916a99ded64 Mon Sep 17 00:00:00 2001 From: Szymon Szlachtowicz <38212223+Szymx95@users.noreply.github.com> Date: Wed, 5 Jan 2022 13:51:12 +0100 Subject: [PATCH] Load community key from env (#175) --- .gitignore | 1 + packages/react-chat-example/package.json | 2 +- packages/react-chat-example/src/index.tsx | 7 +-- packages/react-chat-example/webpack.config.js | 7 ++- .../react-chat/src/components/ChatLoader.tsx | 8 +-- .../react-chat/src/components/ReactChat.tsx | 50 +++++++++---------- .../src/contexts/configProvider.tsx | 24 +++++++++ .../src/contexts/messengerProvider.tsx | 8 +-- .../src/hooks/messenger/useMessenger.ts | 6 ++- packages/react-chat/src/index.ts | 4 +- .../react-chat/src/utils/createMessenger.ts | 35 +++++++++---- packages/status-communities/src/groupChats.ts | 1 + 12 files changed, 94 insertions(+), 59 deletions(-) create mode 100644 packages/react-chat/src/contexts/configProvider.tsx diff --git a/.gitignore b/.gitignore index 89cc6ae8..bdee3fad 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ dist node_modules yarn-error.log .DS_Store +.env build cache diff --git a/packages/react-chat-example/package.json b/packages/react-chat-example/package.json index c263deca..dd020995 100644 --- a/packages/react-chat-example/package.json +++ b/packages/react-chat-example/package.json @@ -9,7 +9,7 @@ "clean:all": "yarn clean && rimraf node_modules/", "clean": "rimraf dist/", "build": "rm -rf dist && webpack --mode=production --env ENV=production", - "start": "webpack serve --mode=development --env ENV=development --https", + "start": "webpack serve --mode=development --env ENV=$ENV COMMUNITY_KEY=$COMMUNITY_KEY --https", "fix": "run-s 'fix:*'", "fix:prettier": "prettier './{src,test}/**/*.{ts,tsx}' \"./*.json\" --write", "fix:lint": "eslint './{src,test}/**/*.{ts,tsx}' --fix", diff --git a/packages/react-chat-example/src/index.tsx b/packages/react-chat-example/src/index.tsx index 96885d23..e9a2e04f 100644 --- a/packages/react-chat-example/src/index.tsx +++ b/packages/react-chat-example/src/index.tsx @@ -75,9 +75,10 @@ function DragDiv() { diff --git a/packages/react-chat-example/webpack.config.js b/packages/react-chat-example/webpack.config.js index fb7902db..e4a4585b 100644 --- a/packages/react-chat-example/webpack.config.js +++ b/packages/react-chat-example/webpack.config.js @@ -5,10 +5,8 @@ const webpack = require('webpack'); const { ESBuildMinifyPlugin } = require('esbuild-loader'); module.exports = env => { - let environment = 'development'; - if (env.ENV) { - environment = env.ENV; - } + const environment = env.ENV || 'development'; + const communityKey = env.COMMUNITY_KEY || ''; return { entry: './src/index.tsx', @@ -71,6 +69,7 @@ module.exports = env => { }), new webpack.DefinePlugin({ 'process.env.ENV': JSON.stringify(environment), + 'process.env.COMMUNITY_KEY': JSON.stringify(communityKey), }), new webpack.ProvidePlugin({ process: 'process/browser.js', diff --git a/packages/react-chat/src/components/ChatLoader.tsx b/packages/react-chat/src/components/ChatLoader.tsx index 54d1f8ee..135cdb4c 100644 --- a/packages/react-chat/src/components/ChatLoader.tsx +++ b/packages/react-chat/src/components/ChatLoader.tsx @@ -11,17 +11,13 @@ import { import { Chat } from "./Chat"; import { IdentityLoader } from "./Form/IdentityLoader"; -interface ChatLoaderProps { - communityKey: string; -} - -export function ChatLoader({ communityKey }: ChatLoaderProps) { +export function ChatLoader() { const [userCreationState] = useUserCreationState(); if (userCreationState === UserCreationState.NotCreating) return ( - + diff --git a/packages/react-chat/src/components/ReactChat.tsx b/packages/react-chat/src/components/ReactChat.tsx index 5c84a5be..2cac6e07 100644 --- a/packages/react-chat/src/components/ReactChat.tsx +++ b/packages/react-chat/src/components/ReactChat.tsx @@ -2,7 +2,9 @@ import React, { useRef } from "react"; import { ThemeProvider } from "styled-components"; import styled from "styled-components"; +import { ConfigType } from ".."; import { ActivityProvider } from "../contexts/activityProvider"; +import { ConfigProvider } from "../contexts/configProvider"; import { FetchMetadataProvider } from "../contexts/fetchMetadataProvider"; import { ModalProvider } from "../contexts/modalProvider"; import { NarrowProvider } from "../contexts/narrowProvider"; @@ -16,36 +18,34 @@ import { ChatLoader } from "./ChatLoader"; interface ReactChatProps { theme: Theme; - communityKey: string; + config: ConfigType; fetchMetadata?: (url: string) => Promise; } -export function ReactChat({ - theme, - communityKey, - fetchMetadata, -}: ReactChatProps) { +export function ReactChat({ theme, config, fetchMetadata }: ReactChatProps) { const ref = useRef(null); return ( - - - - - - - - - - -