Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use componentDidMount as sync method #366

Merged
merged 1 commit into from
Feb 7, 2025
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
6 changes: 4 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ class App extends Component {
};
}

async componentDidMount() {
this.setState({ user: await campus.getCurrentUser(true) });
componentDidMount() {
campus.getCurrentUser(true).then(user => {
this.setState({ user });
});
}

render() {
Expand Down
14 changes: 1 addition & 13 deletions src/components/Bb/BbList.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,7 @@ class BbList extends React.Component {
};
}

async componentDidMount() {
const response = await campus.getBulletinBoardForCurrentUser(
1,
this.state.pageSize,
);

if (!!response) {
this.setState({
items: response.data,
activePage: 1,
paging: response.paging,
});
}
componentDidMount() {
}

dateToString = (date) =>
Expand Down
19 changes: 12 additions & 7 deletions src/components/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,26 @@ class Home extends React.Component {
user: null,
};

async componentDidMount() {
componentDidMount() {
this.initializeUser();
}

initializeUser = async () => {
const user = await campus.getCurrentUser();

if (!user) {
this.props.history.push('/login');
return;
} else {
if (!user.modules) {
await campus.logout();
window.location.href = 'https://ecampus.kpi.ua/';
}
}

if (!user.modules) {
await campus.logout();
window.location.href = 'https://ecampus.kpi.ua/';
return;
}

this.setState({ user });
}
};

redirectToOldUI = async (e) => {
e.preventDefault();
Expand Down
8 changes: 6 additions & 2 deletions src/components/KPIID.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ class KpiId extends React.Component {
super(props);
}

componentDidMount = async () => {
componentDidMount() {
this.handleAuthentication();
}

handleAuthentication = async () => {
try {
const params = new URLSearchParams(this.props.location.search);
const ticketId = params.get('ticketId');
Expand All @@ -24,7 +28,7 @@ class KpiId extends React.Component {

const currentUser = await campus.exchangeKpiIdTicket(ticketId);

if (!!currentUser) {
if (currentUser) {
this.setState({ redirect: '/home' });
} else {
this.setState({ error: 'Failed to authenticate using KPI ID' });
Expand Down
8 changes: 6 additions & 2 deletions src/components/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ class Login extends React.Component {
redirect: null
};

componentDidMount = async () => {
componentDidMount() {
this.authenticateUser();
}

authenticateUser = async () => {
try {
const currentUser = await campus.getCurrentUser(true);

if (!!currentUser) {
if (currentUser) {
this.setState({ redirect: '/home' });
} else {
this.setState({ error: 'Failed to authenticate using KPI ID' });
Expand Down
8 changes: 6 additions & 2 deletions src/components/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ class Settings extends React.Component {
user: {},
};

async componentDidMount() {
componentDidMount() {
this.loadUser();
}

loadUser = async () => {
const user = await campus.getCurrentUser(true);

if (!user) {
Expand All @@ -18,7 +22,7 @@ class Settings extends React.Component {
}

this.setState({ user });
}
};

render() {
const { user } = this.state;
Expand Down
26 changes: 16 additions & 10 deletions src/components/SettingsEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,29 @@ class SettingsEditor extends React.Component {
redirect: null
};

async componentDidMount() {
componentDidMount() {
this.loadUser();
}

loadUser = async () => {
const user = await campus.getCurrentUser();

if (!user) {
this.props.history.push('/login');
return;
}

this.setState({ user });
this.setState({ email: user.email });
this.setState({ credo: user.credo });
this.setState({ scientificInterests: user.scientificInterests });
this.setState({ fullName: user.fullName });
this.setState({ currentPassword: '' });
this.setState({ password: '' });
this.setState({ passwordConfirmation: '' });
}
this.setState({
user,
email: user.email,
credo: user.credo,
scientificInterests: user.scientificInterests,
fullName: user.fullName,
currentPassword: '',
password: '',
passwordConfirmation: '',
});
};

/**
* Validate password
Expand Down
2 changes: 1 addition & 1 deletion src/components/UserProfileImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class UserProfileImage extends React.Component {
rnd: 0,
};

async componentDidMount() {
componentDidMount() {
this.setState({ rnd: getRandomNumber() });
}

Expand Down