-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
261 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,6 @@ | ||
import { onAlert, onCrossContextConfirm } from '~/base/infra/chrome-extension'; | ||
import createEventBus from '~/base/infra/event-bus'; | ||
import { runApp } from './runApp'; | ||
|
||
createEventBus('isolated'); | ||
|
||
onCrossContextConfirm('isolated', (message) => { | ||
const isConfirm = confirm(message); | ||
return isConfirm; | ||
}); | ||
|
||
onAlert((message) => { | ||
alert(message); | ||
}); | ||
runApp(); |
4 changes: 4 additions & 0 deletions
4
src/app/chrome-extension/scripts/common-isolated/isolated.css
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,4 @@ | ||
/* 백준 전역 css override */ | ||
html { | ||
font-size: initial; | ||
} |
28 changes: 28 additions & 0 deletions
28
src/app/chrome-extension/scripts/common-isolated/runApp.tsx
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,28 @@ | ||
import type { ReactElement } from 'react'; | ||
import { createRoot } from 'react-dom/client'; | ||
import { AlertProvider } from '@base/components/Alert'; | ||
import { ConfirmProvider } from '@base/components/Confirm'; | ||
import { ProblemSolvingPage } from '~/pages/problem-solving'; | ||
import '~/app/index.css'; | ||
import './isolated.css'; | ||
|
||
function Panel({ children }: { children: ReactElement }) { | ||
return ( | ||
<div className="fixed right-5 top-5 z-[100] min-w-[350px]">{children}</div> | ||
); | ||
} | ||
|
||
export function runApp() { | ||
const $div = document.createElement('div'); | ||
|
||
document.body.append($div); | ||
|
||
const root = createRoot($div); | ||
root.render( | ||
<AlertProvider Wrapper={Panel}> | ||
<ConfirmProvider Wrapper={Panel}> | ||
<ProblemSolvingPage /> | ||
</ConfirmProvider> | ||
</AlertProvider>, | ||
); | ||
} |
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 |
---|---|---|
|
@@ -2,8 +2,8 @@ | |
"manifest_version": 3, | ||
"name": "Code-Vault", | ||
"description": "Code-Vault에서 제공하는 크롬 확장도구입니다.", | ||
"version": "1.0.0.3", | ||
"version_name": "1.0.0-beta.3", | ||
"version": "1.0.0.4", | ||
"version_name": "1.0.0-beta.4", | ||
"author": "[email protected]", | ||
"homepage_url": "https://github.com/woong-jae/code-vault", | ||
"action": {}, | ||
|
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,80 @@ | ||
import { createPortal } from 'react-dom'; | ||
import { | ||
Card, | ||
CardDescription, | ||
CardFooter, | ||
CardHeader, | ||
CardTitle, | ||
} from '../Card'; | ||
import { Button } from '../Button'; | ||
import { | ||
createContext, | ||
useContext, | ||
useState, | ||
type ReactElement, | ||
useCallback, | ||
} from 'react'; | ||
|
||
type AlertContent = { | ||
title: string; | ||
description: string; | ||
}; | ||
|
||
const AlertContext = createContext<{ | ||
alert: (content: AlertContent) => void; | ||
}>({ | ||
alert: () => {}, | ||
}); | ||
|
||
export function AlertProvider({ | ||
children, | ||
Wrapper, | ||
}: { | ||
children: ReactElement; | ||
Wrapper: (prop: { children: ReactElement }) => ReactElement; | ||
}) { | ||
const [isAlerting, setIsAlerting] = useState(false); | ||
const [content, setContent] = useState<AlertContent>({ | ||
title: '', | ||
description: '', | ||
}); | ||
|
||
const alert = useCallback( | ||
(props: AlertContent) => { | ||
setContent(props); | ||
setIsAlerting(true); | ||
}, | ||
[setIsAlerting, setContent], | ||
); | ||
|
||
return ( | ||
<AlertContext.Provider | ||
value={{ | ||
alert, | ||
}} | ||
> | ||
{children} | ||
{isAlerting && | ||
createPortal( | ||
<Wrapper> | ||
<Card> | ||
<CardHeader> | ||
<CardTitle>{content.title}</CardTitle> | ||
<CardDescription>{content.description}</CardDescription> | ||
</CardHeader> | ||
<CardFooter className="flex flex-row-reverse"> | ||
<Button size="sm" onClick={() => setIsAlerting(false)}> | ||
확인 | ||
</Button> | ||
</CardFooter> | ||
</Card> | ||
</Wrapper>, | ||
document.body, | ||
)} | ||
</AlertContext.Provider> | ||
); | ||
} | ||
|
||
export function useAlert() { | ||
return useContext(AlertContext); | ||
} |
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 @@ | ||
export * from './alert'; |
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,98 @@ | ||
import { createPortal } from 'react-dom'; | ||
import { | ||
Card, | ||
CardDescription, | ||
CardFooter, | ||
CardHeader, | ||
CardTitle, | ||
} from '../Card'; | ||
import { Button } from '../Button'; | ||
import { | ||
createContext, | ||
useContext, | ||
useState, | ||
type ReactElement, | ||
useCallback, | ||
} from 'react'; | ||
|
||
type ConfirmProps = { | ||
title: string; | ||
description: string; | ||
onConfirm: (isConfirmed: boolean) => void; | ||
}; | ||
|
||
const ConfirmContext = createContext<{ | ||
confirm: (props: ConfirmProps) => void; | ||
}>({ | ||
confirm: () => false, | ||
}); | ||
|
||
export function ConfirmProvider({ | ||
children, | ||
Wrapper, | ||
}: { | ||
children: ReactElement; | ||
Wrapper: (prop: { children: ReactElement }) => ReactElement; | ||
}) { | ||
const [isConfirming, setIsConfirming] = useState(false); | ||
const [props, setProps] = useState<ConfirmProps>({ | ||
title: '', | ||
description: '', | ||
onConfirm: () => false, | ||
}); | ||
|
||
const confirm = useCallback( | ||
(props: ConfirmProps) => { | ||
setProps(props); | ||
setIsConfirming(true); | ||
}, | ||
[setIsConfirming, setProps], | ||
); | ||
|
||
return ( | ||
<ConfirmContext.Provider | ||
value={{ | ||
confirm, | ||
}} | ||
> | ||
{children} | ||
{isConfirming && | ||
createPortal( | ||
<Wrapper> | ||
<Card> | ||
<CardHeader> | ||
<CardTitle>{props.title}</CardTitle> | ||
<CardDescription>{props.description}</CardDescription> | ||
</CardHeader> | ||
<CardFooter className="flex flex-row justify-end space-x-2"> | ||
<Button | ||
size="sm" | ||
variant={'outline'} | ||
onClick={() => { | ||
setIsConfirming(false); | ||
props.onConfirm(false); | ||
}} | ||
> | ||
취소 | ||
</Button> | ||
<Button | ||
size="sm" | ||
onClick={() => { | ||
setIsConfirming(false); | ||
props.onConfirm(true); | ||
}} | ||
> | ||
확인 | ||
</Button> | ||
</CardFooter> | ||
</Card> | ||
</Wrapper>, | ||
document.body, | ||
)} | ||
</ConfirmContext.Provider> | ||
); | ||
} | ||
|
||
export function useConfirm() { | ||
return useContext(ConfirmContext); | ||
} |
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 @@ | ||
export * from './confirm'; |
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,30 @@ | ||
import { useEffect } from 'react'; | ||
import { useAlert } from '@base/components/Alert'; | ||
import { useConfirm } from '@base/components/Confirm'; | ||
import { onAlert, onCrossContextConfirm } from '@base/infra/chrome-extension'; | ||
|
||
export function ProblemSolvingPage() { | ||
const { alert } = useAlert(); | ||
const { confirm } = useConfirm(); | ||
|
||
useEffect(() => { | ||
onAlert((message) => { | ||
alert({ | ||
title: '알림', | ||
description: message, | ||
}); | ||
}); | ||
}, [alert]); | ||
|
||
useEffect(() => { | ||
onCrossContextConfirm('isolated', (message, onConfirm) => { | ||
confirm({ | ||
title: '알림', | ||
description: message, | ||
onConfirm, | ||
}); | ||
}); | ||
}, [confirm]); | ||
|
||
return <></>; | ||
} |