arunoda / react-komposer

Feed data into React components by composing containers.
MIT License
732 stars 70 forks source link

Get the values from Response in SharePoint SPFx #180

Closed gargankush010 closed 5 years ago

gargankush010 commented 5 years ago

Hi Everyone,

I am new to SPFx so please bear with my foolish mistakes. I am trying to make a webpart which gets the current logged in user's 'Following sites' using pnp. I got the URLs of following sites and i can see the returned promise in console as well. I just dont know how should i resolve this Response. Please help. `import { Version } from '@microsoft/sp-core-library'; import { BaseClientSideWebPart } from '@microsoft/sp-webpart-base'; import { IPropertyPaneConfiguration, PropertyPaneTextField } from '@microsoft/sp-property-pane'; import { escape } from '@microsoft/sp-lodash-subset';

import styles from './MyfavoritesWpWebPart.module.scss'; import * as strings from 'MyfavoritesWpWebPartStrings'; import { sp, SocialActorTypes } from "@pnp/sp";

export interface IMyfavoritesWpWebPartProps { description: string; allfavoritessitesurl: favoritesitesurl[]; } export interface favoritesitesurl { ContentUri: string; } export default class MyfavoritesWpWebPart extends BaseClientSideWebPart {

public render(): void {

//this.getFollowedSites().then(()=>{

//});
this.domElement.innerHTML = `
  <div class="${ styles.myfavoritesWp }">
    <div class="${ styles.container }">
      <div class="${ styles.row }">
        <div class="${ styles.column }">
          <span class="${ styles.title }">Welcome to SharePoint!</span>
          <p class="${ styles.subTitle }">Customize SharePoint experiences using Web Parts.</p>
          <p class="${ styles.description }">${escape(this.properties.description)}</p>
          <a href="https://aka.ms/spfx" class="${ styles.button }">
            <span class="${ styles.label }">Learn more</span>
          </a>
        </div>
      </div>
    </div>
  </div>`;
 this.followedSites();

}

private followedSites(): void{ this.getFollowedSites().then((Response)=>{ var options: Array = new Array(); console.log("Response is : ",Response); Response.value.map(()=> { options.push({ContentUri: Response.ContentUri}); });

  console.log(options);

});

}

public async getFollowedSites() :Promise { const uri = await sp.social.my.followed(SocialActorTypes.Site); console.log(uri); return uri;

}

protected get dataVersion(): Version { return Version.parse('1.0'); }

protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration { return { pages: [ { header: { description: strings.PropertyPaneDescription }, groups: [ { groupName: strings.BasicGroupName, groupFields: [ PropertyPaneTextField('description', { label: strings.DescriptionFieldLabel }) ] } ] } ] }; } } `

gargankush010 commented 5 years ago

i got it. For my fellow newbie SPFx developers, i am posting my solution. Just replace the followedsites() method with this.

private followedSites(): void{ this.getFollowedSites().then((Response)=>{ var options: Array<favoritesitesurl> = new Array<favoritesitesurl>(); console.log("Response is : ",Response); Response.forEach(element => { console.log(element.ContentUri); }); }); }