From 4a28f25347addf05708cdff37ecace4139f01779 Mon Sep 17 00:00:00 2001
From: Luke Granger-Brown <git@lukegb.com>
Date: Thu, 18 Jun 2020 02:52:33 +0100
Subject: Add support for read-only mode for web UI.

Fixes #402.
---
 webui/src/layout/CurrentIdentity.tsx | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)

(limited to 'webui/src/layout/CurrentIdentity.tsx')

diff --git a/webui/src/layout/CurrentIdentity.tsx b/webui/src/layout/CurrentIdentity.tsx
index 21f489ef..55060179 100644
--- a/webui/src/layout/CurrentIdentity.tsx
+++ b/webui/src/layout/CurrentIdentity.tsx
@@ -3,7 +3,7 @@ import React from 'react';
 import Avatar from '@material-ui/core/Avatar';
 import { makeStyles } from '@material-ui/core/styles';
 
-import { useCurrentIdentityQuery } from './CurrentIdentity.generated';
+import CurrentIdentityContext from './CurrentIdentityContext';
 
 const useStyles = makeStyles(theme => ({
   displayName: {
@@ -13,18 +13,26 @@ const useStyles = makeStyles(theme => ({
 
 const CurrentIdentity = () => {
   const classes = useStyles();
-  const { loading, error, data } = useCurrentIdentityQuery();
 
-  if (error || loading || !data?.repository?.userIdentity) return null;
-
-  const user = data.repository.userIdentity;
   return (
-    <>
-      <Avatar src={user.avatarUrl ? user.avatarUrl : undefined}>
-        {user.displayName.charAt(0).toUpperCase()}
-      </Avatar>
-      <div className={classes.displayName}>{user.displayName}</div>
-    </>
+    <CurrentIdentityContext.Consumer>
+      {context => {
+        if (!context) return null;
+        const { loading, error, data } = context as any;
+
+        if (error || loading || !data?.repository?.userIdentity) return null;
+
+        const user = data.repository.userIdentity;
+        return (
+          <>
+            <Avatar src={user.avatarUrl ? user.avatarUrl : undefined}>
+              {user.displayName.charAt(0).toUpperCase()}
+            </Avatar>
+            <div className={classes.displayName}>{user.displayName}</div>
+          </>
+        );
+      }}
+    </CurrentIdentityContext.Consumer>
   );
 };
 
-- 
cgit 

