-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#906 Reset resource after cancel edit
- Loading branch information
Showing
13 changed files
with
201 additions
and
115 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
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { ResourceEvents, type Resource } from '@tomic/react'; | ||
import { useEffect, useState } from 'react'; | ||
import styled from 'styled-components'; | ||
|
||
interface UnsavedIndicatorProps { | ||
resource: Resource; | ||
} | ||
|
||
export const UnsavedIndicator: React.FC<UnsavedIndicatorProps> = ({ | ||
resource, | ||
}) => { | ||
const [hasChanges, setHasChanges] = useState(resource.hasUnsavedChanges()); | ||
|
||
useEffect(() => { | ||
setHasChanges(resource.hasUnsavedChanges()); | ||
|
||
return resource.on(ResourceEvents.LocalChange, () => { | ||
setHasChanges(resource.hasUnsavedChanges()); | ||
}); | ||
}, [resource]); | ||
|
||
if (!hasChanges) { | ||
return null; | ||
} | ||
|
||
return <Indicator>*</Indicator>; | ||
}; | ||
|
||
const Indicator = styled.span` | ||
color: ${p => p.theme.colors.warning}; | ||
`; |
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.