Skip to content

Instantly share code, notes, and snippets.

@jibrel
Last active December 31, 2021 00:24
Show Gist options
  • Save jibrel/8be19dcd023643e5e72ecec254d44f2f to your computer and use it in GitHub Desktop.
Save jibrel/8be19dcd023643e5e72ecec254d44f2f to your computer and use it in GitHub Desktop.
react.js
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