Skip to content

Commit

Permalink
hotfix: fix toast condition
Browse files Browse the repository at this point in the history
  • Loading branch information
Najeong-Kim committed Nov 9, 2024
1 parent cb76bd0 commit 3610e61
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/features/slop/ui/slop-camera.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import calculateWebcamScaleRatio from '../lib/calculateWebcamScale';
import SlopVideo from './slop-video';

interface SlopWebcamProps {
isWebview?: boolean;
webcam: Webcam;
webcamScale: number;
isOpen: boolean;
Expand All @@ -22,6 +23,7 @@ interface SlopWebcamProps {
}

const SlopCamera = ({
isWebview = false,
webcam: { scale, name, position, src, id },
webcamScale,
isOpen,
Expand All @@ -46,7 +48,7 @@ const SlopCamera = ({
setOpenCamera();

if (!src) {
postAppMessage('선택한 웹캠은 아직 준비중 이에요', (message) =>
postAppMessage('선택한 웹캠은 아직 준비중 이에요', isWebview, (message) =>
toast(
<>
<NeutralFace /> {message}
Expand Down
22 changes: 13 additions & 9 deletions src/shared/lib/postAppMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,26 @@ declare global {
}
}

const postAppMessage = (message: string, showToast: (message: string) => void) => {
const postAppMessage = (message: string, isWebview: boolean, showToast: (message: string) => void) => {
const userAgent = navigator.userAgent.toLowerCase();
const android = userAgent.match(/android/i);
const iphone = userAgent.match(/iphone/i);

if (android !== null) {
return window.Android.showToast(message);
} else if (iphone !== null) {
if (window.webkit.messageHandlers.weski) {
window.webkit.messageHandlers.weski.postMessage({ method: "showToast", message: message });
if (isWebview) {
if (android !== null) {
return window.Android.showToast(message);
} else if (iphone !== null) {
if (window.webkit.messageHandlers.weski) {
window.webkit.messageHandlers.weski.postMessage({ method: "showToast", message: message });
} else {
console.error("Weski bridge is not available.");
}
} else {
console.error("Weski bridge is not available.");
return showToast(message);
}
} else {
return showToast(message);
}

return showToast(message);
}

export default postAppMessage;
1 change: 1 addition & 0 deletions src/views/webcam/ui/webcam-mobile-map-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const WebCamMobileMapPage = ({ data }: { resortId?: number; data: ResortInfo })
<WebcamMap
ref={ref}
style={style}
isWebview
containerRef={containerRef}
slops={data.slops}
webcams={data.webcams}
Expand Down
13 changes: 12 additions & 1 deletion src/widgets/webcam/ui/webcam-map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { Position, ResortInfo } from '@/entities/slop/model/model';
import { cn } from '@/shared/lib';

interface WebcamMapProps extends ResortInfo {
isWebview?: boolean;
containerRef: React.RefObject<HTMLElement>;
onCameraClick: ({ scale, id }: { scale: number; id: string }) => void;
style: {
Expand All @@ -19,7 +20,16 @@ interface WebcamMapProps extends ResortInfo {

const WebcamMap = forwardRef<HTMLDivElement, WebcamMapProps>(
(
{ slops, webcams, style, MapComponent, onCameraClick, containerRef, updateCameraPosition },
{
isWebview,
slops,
webcams,
style,
MapComponent,
onCameraClick,
containerRef,
updateCameraPosition,
},
ref
) => {
const { selectedSlop } = useSlopStore();
Expand All @@ -33,6 +43,7 @@ const WebcamMap = forwardRef<HTMLDivElement, WebcamMapProps>(

return (
<SlopCamera
isWebview={isWebview}
key={webcam.id}
webcam={webcam}
webcamScale={style.scale.animation.to as number}
Expand Down

0 comments on commit 3610e61

Please sign in to comment.