@@ -2,17 +2,9 @@ import React, { useEffect, useState } from 'react'
22import Button from '../../components/Button'
33import Page from '../../components/Page'
44import { downloadFromS3 } from '../../utils/download'
5+ import { onWsEvent } from '../../websockets'
56import './GroupPhoto.css'
67
7- const HOST = window . location . origin
8- . replace ( / ^ h t t p / , 'ws' )
9- . replace ( '3000' , '3001' )
10- const ws = new WebSocket ( HOST )
11-
12- // `${window.location.protocol === 'https:' ? 'wss' : 'ws'}://${
13- // window.location.hostname
14- // }:${process.env.PORT || 3001}`,
15-
168const GroupPhoto = ( ) => {
179 const [ isLoading , setIsLoading ] = useState ( true )
1810 const [ isGenerating , setIsGenerating ] = useState ( false )
@@ -42,16 +34,14 @@ const GroupPhoto = () => {
4234
4335 useEffect ( ( ) => {
4436 getGroupPhoto ( )
45- ws . onmessage = ( event ) => {
46- const data = JSON . parse ( event . data )
47- if ( data . id !== 'group-photo' ) return
37+ onWsEvent ( 'group-photo' , ( data ) => {
4838 if ( data . status === 200 ) {
4939 setFile ( data . data )
5040 } else {
5141 console . log ( data . message , data . error )
5242 }
5343 setIsGenerating ( false )
54- }
44+ } )
5545 } , [ ] )
5646
5747 const header = < h1 > Create Group Photo</ h1 >
0 commit comments