Skip to content

Commit

Permalink
Add input for AT toast testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Kudinov committed Sep 5, 2024
1 parent c5920d8 commit 541696c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 44 deletions.
38 changes: 28 additions & 10 deletions frontend/app/modules/toast/Toast.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React from 'react'
import React, { FC } from 'react'
import { observer } from 'mobx-react'
import { ToastContainer } from 'react-toastify'
import { createGlobalStyle } from 'styled-components'
import { createGlobalStyle, styled } from 'styled-components'
import 'react-toastify/dist/ReactToastify.css'
import { useStore } from '../../hooks/useStore'

export const GlobalStyle = createGlobalStyle`
const GlobalStyle = createGlobalStyle`
.Toastify__toast-container--bottom-left{
max-width: 360px;
margin-left: 10px;
Expand All @@ -14,11 +16,27 @@ export const GlobalStyle = createGlobalStyle`
}
`

const Toast = () => (
<>
<GlobalStyle />
<ToastContainer />
</>
)
const Input = styled.input`
border: 0;
padding: 0;
margin: 0;
display: block;
height: 1px;
max-height: 1px;
background: transparent;
color: transparent;
`

const Toast: FC = () => {
const { toastStore: store } = useStore()

return (
<>
<GlobalStyle />
<ToastContainer />
<Input value={store.lastText} id="toast-text" />
</>
)
}

export default Toast
export default observer(Toast)
29 changes: 0 additions & 29 deletions frontend/app/modules/toast/ToastInner.tsx

This file was deleted.

13 changes: 9 additions & 4 deletions frontend/app/modules/toast/toast.store.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
import { toast, ToastPosition, TypeOptions } from 'react-toastify'
import { toast, ToastPosition } from 'react-toastify'
import { RootStore } from '../../store/rootStore'
import ToastInner from './ToastInner'
import { makeObservable, observable } from 'mobx'

export class ToastStore {
rootStore: RootStore
isDarkTheme: boolean
@observable lastText: string

constructor(rootStore: RootStore) {
makeObservable(this)

this.rootStore = rootStore
this.isDarkTheme = false
this.lastText = ''
}

setTheme(isDarkTheme: boolean) {
this.isDarkTheme = isDarkTheme
}

showToast(text: string, timeout = 3000) {
this.lastText = text

const toastOptions = {
theme: this.isDarkTheme ? 'dark' : 'light',
position: 'bottom-left' as ToastPosition,
autoClose: timeout,
type: 'info' as TypeOptions,
}

toast(ToastInner({ text }), toastOptions)
toast.info(text, toastOptions)
}
}
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "next-feature-smartapp",
"version": "2.4.1",
"version": "2.4.2",
"description": "SmartApp with all features",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 541696c

Please sign in to comment.