import * as React from "react" ; import { Query } from "react-apollo" ; import { Set } from "immutable" ; import { LoadingMessage } from "@joincivil/components" ; import gql from "graphql-tag" ; import { LISTING_FRAGMENT } from "@joincivil/utils" ; export const newsroomChannelAdminQuery = gql `
  query {
    currentUser {
      uid
      channels {
        role
        channel {
          id
          channelType
          newsroom {
            contractAddress
            name
            charter {
              logoUrl
            }
          }
          listing {
            ...ListingFragment
          }
        }
      }
    }
  }
  ${ LISTING_FRAGMENT }
` ; export interface WithNewsroomChannelAdminListProps { channelType ? : string ; children ( props ) : any ; } export function newsroomChannelsFromQueryData ( data ? ) { if ( data && data . currentUser && data . currentUser . channels && data . currentUser . channels . filter ) { return data . currentUser . channels . filter ( ( memberChannel ) => memberChannel . role === "admin" && memberChannel . channel . channelType === "newsroom" ) . map ( ( memberChannel ) => memberChannel . channel ) ; } else { return [ ] ; } } export default ( props ) => { return ( < Query query = { newsroomChannelAdminQuery } > { ( { error , loading , data } ) => { if ( loading ) { return < LoadingMessage />; } if ( error ) { console . error ( "Error loading current user channels:" , error ) ; } const newsrooms = newsroomChannelsFromQueryData ( data ) ; return props . children ( { newsrooms : Set ( newsrooms ) } ) ; } } < /Query>); } ;