Skip to content
This repository has been archived by the owner on May 19, 2019. It is now read-only.

Commit

Permalink
Merge pull request #12 from ppeerttu/development
Browse files Browse the repository at this point in the history
Minor fixes
  • Loading branch information
ppeerttu authored Dec 30, 2017
2 parents 68ce20f + d765a05 commit 2d8bcca
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 53 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# chat-frontend

Front end for [Slack](https://slack.com)-ish chat application.
Front end for a hobby chat application.
Author Perttu Kärnä

## Tech stack
Expand Down Expand Up @@ -48,9 +48,12 @@ To wrap these two into together, we use objects called [Observables](https://xgr

### To run the development server

See commands above for each step.

1. Install dependencies
2. Configure API url at src/environments (default http://localhost:3000)
3. Run the development server
* The front end should be available at http://localhost:4200
4. Stop the server by **Ctrl + C**

## Thanks to
Expand Down
54 changes: 27 additions & 27 deletions src/app/middleware/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,31 +76,31 @@ export default () => next => action => {
const [requestType, successType, errorType] = types;
// Forwards requestType action down the middleware stack
next(actionWith({type: requestType, data: data}));
return request(method, path, data).then(
res => {
let type;
if (res.status >= 400) {
type = errorType;
return res.text().then(textData => {
return next(actionWith(filterToken({
res: textData,
type: type
})));
});
} else {
type = successType;
return res.json().then(jsonData => {
return next(actionWith(filterToken({
res: jsonData,
type: type
})));
});
}
}).catch(err => {
console.error(err);
return next(actionWith(filterToken({
error: 'Not able to connect to the service.',
type: errorType
})));
})
return request(method, path, data)
.then(res => {
let type;
if (res.status >= 400) {
type = errorType;
return res.text().then(textData => {
return next(actionWith(filterToken({
res: textData,
type: type
})));
});
} else {
type = successType;
return res.json().then(jsonData => {
return next(actionWith(filterToken({
res: jsonData,
type: type
})));
});
}
}).catch(err => {
console.error(err);
return next(actionWith(filterToken({
error: 'Not able to connect to the service.',
type: errorType
})));
})
};
11 changes: 5 additions & 6 deletions src/app/reducers/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ const types = {
};

export function apiReducer(state: AppState = INITIAL_STATE, action: ChatAction): AppState {

if (action.type.includes(types.REQUEST)) {
return Object.assign({}, state, {
waiting: true
});
}
if (action.type.includes(types.SUCCESS)) {
return Object.assign({}, state, {
waiting: false
Expand All @@ -24,6 +18,11 @@ export function apiReducer(state: AppState = INITIAL_STATE, action: ChatAction):
waiting: false
});
}
if (action.type.includes(types.REQUEST)) {
return Object.assign({}, state, {
waiting: true
});
}

return Object.assign({}, state);
}
3 changes: 2 additions & 1 deletion src/app/views/chat/chat.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class ChatComponent {
return this.chatAction.openSocket().then(() => {
if (this.user === null || this.user === undefined) {
// Get user data and refresh token
this.userAction.refreshToken()
return this.userAction.refreshToken()
.then(action => {
if (
action.type === UserActions.TOKEN_REQUEST_FAILED
Expand Down Expand Up @@ -90,6 +90,7 @@ export class ChatComponent {
if (window.localStorage) {
window.localStorage.removeItem('token');
}
this.router.navigateByUrl('/login');
});
}

Expand Down
3 changes: 3 additions & 0 deletions src/app/views/chat/participants/participants.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<div class="header-container">
<h4>Participants</h4>
</div>
<p id="no-room" *ngIf="!roomId">
No room selected! Select a room from My rooms to view participants.
</p>
<div *ngFor="let user of users" class="user-element">
<i class="material-icons">account_box</i>
<p>
Expand Down
5 changes: 5 additions & 0 deletions src/app/views/chat/participants/participants.component.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
@import '../../../../styles.scss';

#no-room {
margin: 10px;
}


.header-container {
background-color: mat-color($chat-app-primary, 700);
width: 100%;
Expand Down
2 changes: 1 addition & 1 deletion src/app/views/chat/participants/participants.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ export class ParticipantsComponent {
@select() roomsIn$:Observable<RoomInfo[]>;
@select() viewRoom$:Observable<number>;
users: User[];
roomId: number;

private rooms: RoomInfo[];
private roomId: number;
private roomsInSub;
private viewRoomSub;

Expand Down
17 changes: 0 additions & 17 deletions src/app/views/chat/settings/settings.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,3 @@
<a (click)="logout()" class="logout">Log out</a>
</li>
</ul>

<!--
<mat-list>
<mat-list-item>
<button class="nav-item" (click)="openProfileModal()" mat-button>Profile <i class="material-icons">account_circle</i></button>
</mat-list-item>
<mat-list-item>
<button class="nav-item" mat-button (click)="goToAbout()">About <i class="material-icons">info</i></button>
</mat-list-item>
<mat-list-item>
<button class="nav-item" mat-button (click)="goToHelp()">Help <i class="material-icons">help</i></button>
</mat-list-item>
<mat-list-item>
<button class="nav-item" mat-button color="warn" (click)="logout()">Log out <i class="fa fa-sign-out fa-2"></i></button>
</mat-list-item>
</mat-list>
-->

0 comments on commit 2d8bcca

Please sign in to comment.