-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #201 from secretkeylabs/imamahzafar/tab-close-request
handle when a tab that initiated a request is closed
- Loading branch information
Showing
9 changed files
with
174 additions
and
122 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import styled from 'styled-components'; | ||
import InfoIcon from '@assets/img/info.svg'; | ||
|
||
const Container = styled.div((props) => ({ | ||
display: 'flex', | ||
flexDirection: 'row', | ||
borderRadius: 12, | ||
alignItems: 'flex-start', | ||
backgroundColor: 'transparent', | ||
padding: props.theme.spacing(8), | ||
marginBottom: props.theme.spacing(6), | ||
border: '1px solid rgba(255, 255, 255, 0.2)', | ||
})); | ||
|
||
const TextContainer = styled.div((props) => ({ | ||
marginLeft: props.theme.spacing(5), | ||
display: 'flex', | ||
flexDirection: 'column', | ||
})); | ||
|
||
const BoldText = styled.h1((props) => ({ | ||
...props.theme.body_bold_m, | ||
color: props.theme.colors.white['0'], | ||
})); | ||
|
||
const SubText = styled.h1((props) => ({ | ||
...props.theme.body_xs, | ||
marginTop: props.theme.spacing(2), | ||
color: props.theme.colors.white['200'], | ||
})); | ||
|
||
const Text = styled.h1((props) => ({ | ||
...props.theme.body_m, | ||
color: props.theme.colors.white['200'], | ||
lineHeight: 1.4, | ||
})); | ||
|
||
interface Props { | ||
titleText?: string; | ||
bodyText: string; | ||
} | ||
|
||
function InfoContainer({ titleText, bodyText }: Props) { | ||
return ( | ||
<Container> | ||
<img src={InfoIcon} alt="alert" /> | ||
<TextContainer> | ||
{titleText ? ( | ||
<> | ||
<BoldText>{titleText}</BoldText> | ||
<SubText>{bodyText}</SubText> | ||
</> | ||
) | ||
: <Text>{bodyText}</Text>} | ||
</TextContainer> | ||
</Container> | ||
); | ||
} | ||
|
||
export default InfoContainer; |
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,21 @@ | ||
import { InternalMethods } from 'content-scripts/message-types'; | ||
import { BackgroundMessages } from 'content-scripts/messages'; | ||
import { useEffect } from 'react'; | ||
|
||
export default function useOnOriginTabClose( | ||
tabId: number, | ||
handler: () => void, | ||
) { | ||
useEffect(() => { | ||
const messageHandler = (message: BackgroundMessages) => { | ||
if (message.method !== InternalMethods.OriginatingTabClosed) return; | ||
if (message.payload.tabId === Number(tabId)) { | ||
handler(); | ||
} | ||
}; | ||
|
||
chrome.runtime.onMessage.addListener(messageHandler); | ||
|
||
return () => chrome.runtime.onMessage.removeListener(handler); | ||
}, []); | ||
} |
Oops, something went wrong.