import { AnyAction } from "redux" ; import { EthAddress , ContentData , StorageHeader } from "@joincivil/typescript-types" ; import { getIPFSContent } from "../../helpers/listingEvents" ; import { CivilHelper } from "../../apis/CivilHelper" ; export enum newsroomActions { ADD_USER_NEWSROOM = "ADD_USER_NEWSROOM" , ADD_CONTENT = "ADD_CONTENT" , FETCH_CONTENT = "FETCH_CONTENT" , ADD_CHARTER_REVISION = "ADD_CHARTER_REVISION" } export const addUserNewsroom = ( address ) : AnyAction => { return { type : newsroomActions . ADD_USER_NEWSROOM , data : address , } ; } ; export const addContent = ( header , content ) : AnyAction => { return { type : newsroomActions . ADD_CONTENT , data : { header , content , } , } ; } ; export const addCharterRevision = ( address , revisionId , header ) => { return { type : newsroomActions . ADD_CHARTER_REVISION , data : { address , revisionId , header , } , } ; } ; export const fetchContent = ( header ) : AnyAction => { return { type : newsroomActions . FETCH_CONTENT , data : header , } ; } ; export const getContent = ( helper , header ) : any => { return async ( dispatch , getState ) : Promise < AnyAction | void > => { const contentFetched = getState ( ) . networkDependent . contentFetched ; if ( ! contentFetched . has ( header . uri ) ) { dispatch ( fetchContent ( header ) ) ; await getIPFSContent ( helper , header , dispatch ) ; } } ; } ; export const getBareContent = ( helper , uri ) : any => { return async ( dispatch , getState ) : Promise < AnyAction | void > => { const contentFetched = getState ( ) . networkDependent . contentFetched ; if ( ! contentFetched . has ( uri ) ) { await getIPFSContent ( helper , { uri } , dispatch ) ; dispatch ( fetchContent ( { uri } ) ) ; } } ; } ;