-
Notifications
You must be signed in to change notification settings - Fork 1
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 #281 from Team-Ampersand/revert-273-fix/channel-talk
Revert 🔀: 로그인 화면에 채널톡 아이콘 문제 해결
- Loading branch information
Showing
5 changed files
with
63 additions
and
103 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 |
---|---|---|
@@ -1,81 +1,53 @@ | ||
/* eslint-disable @next/next/inline-script-id */ | ||
import Script from 'next/script'; | ||
import { useEffect } from 'react'; | ||
|
||
const ChannelIOScript = ({ | ||
stunumName, | ||
theme, | ||
}: { | ||
stunumName: string; | ||
theme: string; | ||
}) => { | ||
useEffect(() => { | ||
if (!stunumName) { | ||
if (window.ChannelIO) { | ||
window.ChannelIO('shutdown'); | ||
delete window.ChannelIO; | ||
delete window.ChannelIOInitialized; | ||
} | ||
return; | ||
} | ||
const ChannelIOScript = ({stunumName,theme}:{stunumName:string,theme:string}) => ( | ||
<Script | ||
dangerouslySetInnerHTML={{ | ||
__html: `(function() { | ||
var w = window; | ||
if (w.ChannelIO) { | ||
return (window.console.error || window.console.log || function(){})('ChannelIO script included twice.'); | ||
} | ||
var ch = function() { | ||
ch.c(arguments); | ||
}; | ||
ch.q = []; | ||
ch.c = function(args) { | ||
ch.q.push(args); | ||
}; | ||
w.ChannelIO = ch; | ||
function l() { | ||
if (w.ChannelIOInitialized) { | ||
return; | ||
} | ||
w.ChannelIOInitialized = true; | ||
var s = document.createElement('script'); | ||
s.type = 'text/javascript'; | ||
s.async = true; | ||
s.src = 'https://cdn.channel.io/plugin/ch-plugin-web.js'; | ||
s.charset = 'UTF-8'; | ||
var x = document.getElementsByTagName('script')[0]; | ||
x.parentNode.insertBefore(s, x); | ||
} | ||
if (document.readyState === 'complete') { | ||
l(); | ||
} else if (window.attachEvent) { | ||
window.attachEvent('onload', l); | ||
} else { | ||
window.addEventListener('DOMContentLoaded', l, false); | ||
window.addEventListener('load', l, false); | ||
} | ||
})(); | ||
ChannelIO('boot', { | ||
"pluginKey": "${process.env.NEXT_PUBLIC_CHANNEL_IO_KEY}", | ||
"profile": { | ||
"name": "${stunumName}", | ||
} | ||
}); | ||
ChannelIO('setAppearance', '${theme}') | ||
`}} | ||
/> | ||
); | ||
|
||
const initScript = document.createElement('script'); | ||
initScript.innerHTML = ` | ||
(function() { | ||
var w = window; | ||
if (w.ChannelIO) { | ||
return (window.console.error || window.console.log || function() {})('ChannelIO script included twice.'); | ||
} | ||
var ch = function() { | ||
ch.c(arguments); | ||
}; | ||
ch.q = []; | ||
ch.c = function(args) { | ||
ch.q.push(args); | ||
}; | ||
w.ChannelIO = ch; | ||
function l() { | ||
if (w.ChannelIOInitialized) { | ||
return; | ||
} | ||
w.ChannelIOInitialized = true; | ||
var s = document.createElement('script'); | ||
s.type = 'text/javascript'; | ||
s.async = true; | ||
s.src = 'https://cdn.channel.io/plugin/ch-plugin-web.js'; | ||
s.charset = 'UTF-8'; | ||
var x = document.getElementsByTagName('script')[0]; | ||
x.parentNode.insertBefore(s, x); | ||
} | ||
if (document.readyState === 'complete') { | ||
l(); | ||
} else if (window.attachEvent) { | ||
window.attachEvent('onload', l); | ||
} else { | ||
window.addEventListener('DOMContentLoaded', l, false); | ||
window.addEventListener('load', l, false); | ||
} | ||
})(); | ||
ChannelIO('boot', { | ||
"pluginKey": "${process.env.NEXT_PUBLIC_CHANNEL_IO_KEY}", | ||
"profile": { | ||
"name": "${stunumName}", | ||
} | ||
}); | ||
ChannelIO('setAppearance', '${theme}'); | ||
`; | ||
document.body.appendChild(initScript); | ||
|
||
return () => { | ||
if (window.ChannelIO) { | ||
window.ChannelIO('shutdown'); | ||
delete window.ChannelIO; | ||
delete window.ChannelIOInitialized; | ||
} | ||
document.body.removeChild(initScript); | ||
}; | ||
}, [stunumName, theme]); | ||
|
||
return null; | ||
}; | ||
|
||
export default ChannelIOScript; | ||
export default ChannelIOScript; |
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,22 +1,15 @@ | ||
import ChannelIOScript from 'components/Home/atoms/Script/SomeScript'; | ||
import UseToggleTheme from 'hooks/useToggleTheme'; | ||
import { myProfileType } from 'types'; | ||
import { MemberController } from 'utils/Libs/requestUrls'; | ||
import ChannelIOScript from "components/Home/atoms/Script/SomeScript" | ||
import UseToggleTheme from "hooks/useToggleTheme"; | ||
import { myProfileType } from "types"; | ||
import { MemberController } from "utils/Libs/requestUrls"; | ||
import useSWR from 'swr'; | ||
|
||
const ChannelBtn = () => { | ||
const [theme] = UseToggleTheme(); | ||
const { data } = useSWR<myProfileType>(MemberController.myProfile); | ||
return ( | ||
<> | ||
{data ? ( | ||
<ChannelIOScript | ||
stunumName={`${data?.stuNum}${data?.name}`} | ||
theme={theme} | ||
/> | ||
) : null} | ||
</> | ||
); | ||
}; | ||
const [theme,] = UseToggleTheme(); | ||
const { data } = useSWR<myProfileType>(MemberController.myProfile); | ||
return ( | ||
<ChannelIOScript stunumName={`${data?.stuNum}${data?.name}`} theme={theme} /> | ||
) | ||
} | ||
|
||
export default ChannelBtn; | ||
export default ChannelBtn; |
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 was deleted.
Oops, something went wrong.