aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/DevHive.Angular/src/app/app-constants.module.ts8
-rw-r--r--src/DevHive.Angular/src/app/components/feed/feed.component.ts14
-rw-r--r--src/DevHive.Angular/src/app/services/user.service.ts7
3 files changed, 15 insertions, 14 deletions
diff --git a/src/DevHive.Angular/src/app/app-constants.module.ts b/src/DevHive.Angular/src/app/app-constants.module.ts
new file mode 100644
index 0000000..df676da
--- /dev/null
+++ b/src/DevHive.Angular/src/app/app-constants.module.ts
@@ -0,0 +1,8 @@
+export class AppConstants {
+ public static BASE_API_URL = 'http://localhost:5000/api';
+ public static API_USER_URL = AppConstants.BASE_API_URL + '/User';
+ public static API_USER_LOGIN_URL = AppConstants.API_USER_URL + '/login';
+ public static API_USER_REGISTER_URL = AppConstants.API_USER_URL + '/register';
+
+ public static FETCH_TIMEOUT = 500;
+}
diff --git a/src/DevHive.Angular/src/app/components/feed/feed.component.ts b/src/DevHive.Angular/src/app/components/feed/feed.component.ts
index 33e0ba0..83bd4f9 100644
--- a/src/DevHive.Angular/src/app/components/feed/feed.component.ts
+++ b/src/DevHive.Angular/src/app/components/feed/feed.component.ts
@@ -4,6 +4,7 @@ import { Router } from '@angular/router';
import { User } from 'src/models/identity/user';
import { PostComponent } from '../post/post.component';
import { UserService } from '../../services/user.service';
+import { AppConstants } from 'src/app/app-constants.module';
@Component({
selector: 'app-feed',
@@ -12,7 +13,6 @@ import { UserService } from '../../services/user.service';
})
export class FeedComponent implements OnInit {
private _title = 'Feed';
- private _timeoutFetchData = 500;
public dataArrived = false;
public user: User;
public posts: PostComponent[];
@@ -32,16 +32,8 @@ export class FeedComponent implements OnInit {
if (sessionStorage.getItem('UserCred')) {
// Workaround for waiting the fetch response
// TODO: properly wait for it, before loading the page contents
- setTimeout(() =>
- {
- this.user = this._userService.fetchUserFromSessionStorage();
- },
- this._timeoutFetchData);
- setTimeout(() =>
- {
- this.dataArrived = true;
- },
- this._timeoutFetchData + 100);
+ setTimeout(() => { this.user = this._userService.fetchUserFromSessionStorage(); }, AppConstants.FETCH_TIMEOUT);
+ setTimeout(() => { this.dataArrived = true; }, AppConstants.FETCH_TIMEOUT + 100);
} else {
this._router.navigate(['/login']);
}
diff --git a/src/DevHive.Angular/src/app/services/user.service.ts b/src/DevHive.Angular/src/app/services/user.service.ts
index 35215e0..81960f1 100644
--- a/src/DevHive.Angular/src/app/services/user.service.ts
+++ b/src/DevHive.Angular/src/app/services/user.service.ts
@@ -5,6 +5,7 @@ import jwt_decode from 'jwt-decode';
import { IJWTPayload } from '../../interfaces/jwt-payload';
import { IUserCredentials } from '../../interfaces/user-credentials';
import { FormGroup } from '@angular/forms';
+import { AppConstants } from 'src/app/app-constants.module';
@Injectable({
providedIn: 'root'
@@ -24,7 +25,7 @@ export class UserService {
const fetchedUser: User = new User(Guid.createEmpty(), '', '', '', '');
// Fetch the data and assign it to fetchedUser
- fetch(`http://localhost:5000/api/User?Id=${userId}`, {
+ fetch(AppConstants.API_USER_URL + '?Id=' + userId, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
@@ -39,7 +40,7 @@ export class UserService {
// TODO: make return bool when the response is an error
loginUser(loginUserFormGroup: FormGroup): void {
// Save the fetch reponse in the sessionStorage
- fetch('http://localhost:5000/api/User/login', {
+ fetch(AppConstants.API_USER_LOGIN_URL, {
method: 'POST',
body: JSON.stringify({
UserName: loginUserFormGroup.get('username')?.value,
@@ -57,7 +58,7 @@ export class UserService {
// TODO: add a check for form data validity
// Like in login, save the fetch reponse in the sessionStorage
- fetch('http://localhost:5000/api/User/register', {
+ fetch(AppConstants.API_USER_REGISTER_URL, {
method: 'POST',
body: JSON.stringify({
UserName: registerUserFormGroup.get('username')?.value,