Last active
December 31, 2021 00:24
-
-
Save jibrel/8be19dcd023643e5e72ecec254d44f2f to your computer and use it in GitHub Desktop.
react.js
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
import React from 'react'; | |
import { Subscription } from 'react-apollo'; | |
import gql from 'graphql-tag'; | |
const ConvertScreen = () => { | |
const urlParams = new URLSearchParams(window.location.search); | |
const id = urlParams.get('id'); | |
return ( | |
<Subscription | |
subscription={ | |
gql` | |
subscription ($id: Int) { | |
images ( | |
where: { | |
id: { | |
_eq: $id | |
} | |
} | |
) { | |
id | |
image_uri | |
converted_image_uri | |
} | |
} | |
` | |
} | |
variables={{id}} | |
> | |
{ | |
({data, error, loading}) => { | |
if (error) { console.error(error); return <ErrorScreen /> } | |
if (loading) return <LoadingScreen />; | |
if (data.images.length === 0) { | |
return "Invalid image ID"; | |
} | |
if (!data.images[0].converted_image_uri) { | |
return <LoadingScreen /> | |
} | |
return ( | |
<ImageScreen | |
original={data.images[0].image_uri} | |
converted={data.images[0].converted_image_uri} | |
/> | |
); | |
} | |
} | |
</Subscription> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment