Skip to content
This repository was archived by the owner on May 25, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,66 +1,73 @@
import React, { Component } from "react";
import { UpdateContext, withWebId } from "@inrupt/solid-react-components";
import { withTranslation } from "react-i18next";
import AuthNavBar from "./auth-nav-bar.component";
import data from "@solid/query-ldflex";
import { withToastManager } from "react-toast-notifications";
import React, { Component } from 'react';
import { UpdateContext, withWebId } from '@inrupt/solid-react-components';
import { withTranslation } from 'react-i18next';
import AuthNavBar from './auth-nav-bar.component';
import data from '@solid/query-ldflex';
import { withToastManager } from 'react-toast-notifications';

let beforeContext = {};

class AuthNavBarContainer extends Component {
constructor(props) {
super(props);
this.state = { image: null };
}

getProfileData = async () => {
try {
// fetching user card from pod. This makes a request and returns the data
const user = data.user;
/*
* In the background LDFlex is using JSON-LD. Because of this, we need to
* make an async call. This will return a JSON-LD expanded object and expose the requested value(name).
* for more information please go to: https://github.com/digitalbazaar/jsonld.js
*/
const userName = await user.name;
const userImage = await user.vcard_hasPhoto;
const name = userName ? userName.value : "";
const image = userImage ? userImage.value : "/img/icon/empty-profile.svg";
this.setState({
name,
image
});
} catch (error) {
this.props.toastManager.add (['Error', error.message], {
appearance: 'error',
});
constructor(props) {
super(props);
this.state = { image: null };
}
};

componentDidMount() {
if (this.props.webId) {
this.getProfileData();
}
}
getProfileData = async () => {
try {
// fetching user card from pod. This makes a request and returns the data
const user = data.user;
/*
* In the background LDFlex is using JSON-LD. Because of this, we need to
* make an async call. This will return a JSON-LD expanded object and expose the requested value(name).
* for more information please go to: https://github.com/digitalbazaar/jsonld.js
*/
const userName = await user.name;
const userImage = await user.vcard_hasPhoto;
const name = userName ? userName.value : '';
const image = userImage
? userImage.value
: '/img/icon/empty-profile.svg';
this.setState({
name,
image,
});
} catch (error) {
this.props.toastManager.add(['Error', error.message], {
appearance: 'error',
autoDismiss: false,
});
}
};

async componentDidUpdate(prevProps, prevState) {
if (this.props.webId && this.props.webId !== prevProps.webId) {
this.getProfileData();
componentDidMount() {
if (this.props.webId) {
this.getProfileData();
}
}

if (this.context && this.context.timestamp !== beforeContext.timestamp) {
this.getProfileData();
async componentDidUpdate(prevProps, prevState) {
if (this.props.webId && this.props.webId !== prevProps.webId) {
this.getProfileData();
}

if (
this.context &&
this.context.timestamp !== beforeContext.timestamp
) {
this.getProfileData();

beforeContext = this.context;
beforeContext = this.context;
}
}
}

render() {
const { image } = this.state;
return <AuthNavBar img={image} {...this.props} {...this.state} />;
}
render() {
const { image } = this.state;
return <AuthNavBar img={image} {...this.props} {...this.state} />;
}
}
AuthNavBarContainer.contextType = UpdateContext;


export default withTranslation()(withToastManager(withWebId(AuthNavBarContainer)));
export default withTranslation()(
withToastManager(withWebId(AuthNavBarContainer))
);
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ export const Image = ({ webId, toastManager, defaultProfilePhoto }: Props) => {
},
onError: error => {
if (error && error.statusText) {
toastManager.add(['', error.statusText], {
toastManager.add(['Error', error.statusText], {
appearance: 'error',
autoDismiss: false,
});
}
},
Expand Down
Loading