-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(ui): migrate several components from class to functional (#1…
…1791) Signed-off-by: Anton Gilgur <agilgur5@gmail.com>
- Loading branch information
Showing
27 changed files
with
443 additions
and
499 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,24 @@ | ||
import * as React from 'react'; | ||
import {useState} from 'react'; | ||
import {Notice} from './notice'; | ||
|
||
export class Nudge extends React.Component<{key: string}, {closed: boolean}> { | ||
constructor(props: Readonly<{key: string}>) { | ||
super(props); | ||
this.state = {closed: localStorage.getItem(props.key) !== null}; | ||
export function Nudge(props: React.PropsWithChildren<{key: string}>) { | ||
const [closed, setClosed] = useState(localStorage.getItem(props.key) !== null); | ||
function close() { | ||
setClosed(true); | ||
localStorage.setItem(props.key, '{}'); | ||
} | ||
|
||
public render() { | ||
return ( | ||
!this.state.closed && ( | ||
<Notice style={{marginLeft: 0, marginRight: 0}}> | ||
{this.props.children} | ||
<span className='fa-pull-right'> | ||
<a onClick={() => this.close()}> | ||
<i className='fa fa-times' /> | ||
</a>{' '} | ||
</span> | ||
</Notice> | ||
) | ||
); | ||
} | ||
|
||
private close() { | ||
this.setState({closed: true}); | ||
localStorage.setItem(this.props.key, '{}'); | ||
} | ||
return ( | ||
!closed && ( | ||
<Notice style={{marginLeft: 0, marginRight: 0}}> | ||
{props.children} | ||
<span className='fa-pull-right'> | ||
<a onClick={() => close()}> | ||
<i className='fa fa-times' /> | ||
</a>{' '} | ||
</span> | ||
</Notice> | ||
) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.