Skip to content

Commit

Permalink
End of section 19
Browse files Browse the repository at this point in the history
  • Loading branch information
TryCatchLearn committed Aug 5, 2023
1 parent a706f02 commit 1762d03
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 17 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/docker-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: docker-push

on:
workflow_dispatch:
# push:
# branches:
# - 'main'
push:
branches:
- 'main'
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
jobs:
Expand Down
4 changes: 0 additions & 4 deletions API/Extensions/ApplicationServiceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ public static class ApplicationServiceExtensions
public static IServiceCollection AddApplicationServices(this IServiceCollection services, IConfiguration config)
{
services.AddScoped<ITokenService, TokenService>();
services.AddDbContext<DataContext>(opt =>
{
opt.UseNpgsql(config.GetConnectionString("DefaultConnection"));
});
services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
services.Configure<CloudinarySettings>(config.GetSection("CloudinarySettings"));
services.AddScoped<IPhotoService, PhotoService>();
Expand Down
18 changes: 18 additions & 0 deletions API/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"CloudinarySettings": {
"CloudName": "dj3wmuy3l",
"ApiKey": "895484589483755",
"ApiSecret": "XrW7lwkfNWgcQwFl_mr379bqUtA"
},
"ConnectionStrings": {
"DefaultConnection": "Server=host.docker.internal; Port=5432; User Id=postgres; Password=postgrespw; Database=datingapp"
},
"TokenKey": "MI54kkSCexeDVZjgL9I9zqUTq6XX8maCJcj2NzfIDXrApRDrDYR3ShZaTRzfLHIR"
}
2 changes: 1 addition & 1 deletion API/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
<style>@import"https://fonts.googleapis.com/css2?family=Ubuntu:wght@400;700&display=swap";:root{--bs-blue:#0d6efd;--bs-indigo:#6610f2;--bs-purple:#6f42c1;--bs-pink:#d63384;--bs-red:#dc3545;--bs-orange:#fd7e14;--bs-yellow:#ffc107;--bs-green:#198754;--bs-teal:#20c997;--bs-cyan:#0dcaf0;--bs-black:#000;--bs-white:#fff;--bs-gray:#6c757d;--bs-gray-dark:#343a40;--bs-gray-100:#f8f9fa;--bs-gray-200:#e9ecef;--bs-gray-300:#dee2e6;--bs-gray-400:#ced4da;--bs-gray-500:#adb5bd;--bs-gray-600:#6c757d;--bs-gray-700:#495057;--bs-gray-800:#343a40;--bs-gray-900:#212529;--bs-primary:#0d6efd;--bs-secondary:#6c757d;--bs-success:#198754;--bs-info:#0dcaf0;--bs-warning:#ffc107;--bs-danger:#dc3545;--bs-light:#f8f9fa;--bs-dark:#212529;--bs-primary-rgb:13,110,253;--bs-secondary-rgb:108,117,125;--bs-success-rgb:25,135,84;--bs-info-rgb:13,202,240;--bs-warning-rgb:255,193,7;--bs-danger-rgb:220,53,69;--bs-light-rgb:248,249,250;--bs-dark-rgb:33,37,41;--bs-primary-text-emphasis:#052c65;--bs-secondary-text-emphasis:#2b2f32;--bs-success-text-emphasis:#0a3622;--bs-info-text-emphasis:#055160;--bs-warning-text-emphasis:#664d03;--bs-danger-text-emphasis:#58151c;--bs-light-text-emphasis:#495057;--bs-dark-text-emphasis:#495057;--bs-primary-bg-subtle:#cfe2ff;--bs-secondary-bg-subtle:#e2e3e5;--bs-success-bg-subtle:#d1e7dd;--bs-info-bg-subtle:#cff4fc;--bs-warning-bg-subtle:#fff3cd;--bs-danger-bg-subtle:#f8d7da;--bs-light-bg-subtle:#fcfcfd;--bs-dark-bg-subtle:#ced4da;--bs-primary-border-subtle:#9ec5fe;--bs-secondary-border-subtle:#c4c8cb;--bs-success-border-subtle:#a3cfbb;--bs-info-border-subtle:#9eeaf9;--bs-warning-border-subtle:#ffe69c;--bs-danger-border-subtle:#f1aeb5;--bs-light-border-subtle:#e9ecef;--bs-dark-border-subtle:#adb5bd;--bs-white-rgb:255,255,255;--bs-black-rgb:0,0,0;--bs-font-sans-serif:system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue","Noto Sans","Liberation Sans",Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";--bs-font-monospace:SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;--bs-gradient:linear-gradient(180deg, rgba(255, 255, 255, .15), rgba(255, 255, 255, 0));--bs-body-font-family:var(--bs-font-sans-serif);--bs-body-font-size:1rem;--bs-body-font-weight:400;--bs-body-line-height:1.5;--bs-body-color:#212529;--bs-body-color-rgb:33,37,41;--bs-body-bg:#fff;--bs-body-bg-rgb:255,255,255;--bs-emphasis-color:#000;--bs-emphasis-color-rgb:0,0,0;--bs-secondary-color:rgba(33, 37, 41, .75);--bs-secondary-color-rgb:33,37,41;--bs-secondary-bg:#e9ecef;--bs-secondary-bg-rgb:233,236,239;--bs-tertiary-color:rgba(33, 37, 41, .5);--bs-tertiary-color-rgb:33,37,41;--bs-tertiary-bg:#f8f9fa;--bs-tertiary-bg-rgb:248,249,250;--bs-heading-color:inherit;--bs-link-color:#0d6efd;--bs-link-color-rgb:13,110,253;--bs-link-decoration:underline;--bs-link-hover-color:#0a58ca;--bs-link-hover-color-rgb:10,88,202;--bs-code-color:#d63384;--bs-highlight-bg:#fff3cd;--bs-border-width:1px;--bs-border-style:solid;--bs-border-color:#dee2e6;--bs-border-color-translucent:rgba(0, 0, 0, .175);--bs-border-radius:.375rem;--bs-border-radius-sm:.25rem;--bs-border-radius-lg:.5rem;--bs-border-radius-xl:1rem;--bs-border-radius-xxl:2rem;--bs-border-radius-2xl:var(--bs-border-radius-xxl);--bs-border-radius-pill:50rem;--bs-box-shadow:0 .5rem 1rem rgba(0, 0, 0, .15);--bs-box-shadow-sm:0 .125rem .25rem rgba(0, 0, 0, .075);--bs-box-shadow-lg:0 1rem 3rem rgba(0, 0, 0, .175);--bs-box-shadow-inset:inset 0 1px 2px rgba(0, 0, 0, .075);--bs-focus-ring-width:.25rem;--bs-focus-ring-opacity:.25;--bs-focus-ring-color:rgba(13, 110, 253, .25);--bs-form-valid-color:#198754;--bs-form-valid-border-color:#198754;--bs-form-invalid-color:#dc3545;--bs-form-invalid-border-color:#dc3545}*,:after,:before{box-sizing:border-box}@media (prefers-reduced-motion:no-preference){:root{scroll-behavior:smooth}}body{margin:0;font-family:var(--bs-body-font-family);font-size:var(--bs-body-font-size);font-weight:var(--bs-body-font-weight);line-height:var(--bs-body-line-height);color:var(--bs-body-color);text-align:var(--bs-body-text-align);background-color:var(--bs-body-bg);-webkit-text-size-adjust:100%;-webkit-tap-highlight-color:transparent}:root{--bs-breakpoint-xs:0;--bs-breakpoint-sm:576px;--bs-breakpoint-md:768px;--bs-breakpoint-lg:992px;--bs-breakpoint-xl:1200px;--bs-breakpoint-xxl:1400px}@charset "UTF-8";:root{--bs-blue:#007bff;--bs-indigo:#6610f2;--bs-purple:#772953;--bs-pink:#e83e8c;--bs-red:#df382c;--bs-orange:#e95420;--bs-yellow:#efb73e;--bs-green:#38b44a;--bs-teal:#20c997;--bs-cyan:#17a2b8;--bs-black:#000;--bs-white:#fff;--bs-gray:#868e96;--bs-gray-dark:#333;--bs-gray-100:#f8f9fa;--bs-gray-200:#e9ecef;--bs-gray-300:#dee2e6;--bs-gray-400:#ced4da;--bs-gray-500:#aea79f;--bs-gray-600:#868e96;--bs-gray-700:#495057;--bs-gray-800:#333;--bs-gray-900:#212529;--bs-primary:#e95420;--bs-secondary:#aea79f;--bs-success:#38b44a;--bs-info:#17a2b8;--bs-warning:#efb73e;--bs-danger:#df382c;--bs-light:#e9ecef;--bs-dark:#772953;--bs-primary-rgb:233, 84, 32;--bs-secondary-rgb:174, 167, 159;--bs-success-rgb:56, 180, 74;--bs-info-rgb:23, 162, 184;--bs-warning-rgb:239, 183, 62;--bs-danger-rgb:223, 56, 44;--bs-light-rgb:233, 236, 239;--bs-dark-rgb:119, 41, 83;--bs-primary-text-emphasis:#5d220d;--bs-secondary-text-emphasis:#464340;--bs-success-text-emphasis:#16481e;--bs-info-text-emphasis:#09414a;--bs-warning-text-emphasis:#604919;--bs-danger-text-emphasis:#591612;--bs-light-text-emphasis:#495057;--bs-dark-text-emphasis:#495057;--bs-primary-bg-subtle:#fbddd2;--bs-secondary-bg-subtle:#efedec;--bs-success-bg-subtle:#d7f0db;--bs-info-bg-subtle:#d1ecf1;--bs-warning-bg-subtle:#fcf1d8;--bs-danger-bg-subtle:#f9d7d5;--bs-light-bg-subtle:#fcfcfd;--bs-dark-bg-subtle:#ced4da;--bs-primary-border-subtle:#f6bba6;--bs-secondary-border-subtle:#dfdcd9;--bs-success-border-subtle:#afe1b7;--bs-info-border-subtle:#a2dae3;--bs-warning-border-subtle:#f9e2b2;--bs-danger-border-subtle:#f2afab;--bs-light-border-subtle:#e9ecef;--bs-dark-border-subtle:#aea79f;--bs-white-rgb:255, 255, 255;--bs-black-rgb:0, 0, 0;--bs-font-sans-serif:Ubuntu, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";--bs-font-monospace:SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;--bs-gradient:linear-gradient(180deg, rgba(255, 255, 255, .15), rgba(255, 255, 255, 0));--bs-body-font-family:var(--bs-font-sans-serif);--bs-body-font-size:1rem;--bs-body-font-weight:400;--bs-body-line-height:1.5;--bs-body-color:#333;--bs-body-color-rgb:51, 51, 51;--bs-body-bg:#fff;--bs-body-bg-rgb:255, 255, 255;--bs-emphasis-color:#000;--bs-emphasis-color-rgb:0, 0, 0;--bs-secondary-color:rgba(51, 51, 51, .75);--bs-secondary-color-rgb:51, 51, 51;--bs-secondary-bg:#e9ecef;--bs-secondary-bg-rgb:233, 236, 239;--bs-tertiary-color:rgba(51, 51, 51, .5);--bs-tertiary-color-rgb:51, 51, 51;--bs-tertiary-bg:#f8f9fa;--bs-tertiary-bg-rgb:248, 249, 250;--bs-heading-color:inherit;--bs-link-color:#e95420;--bs-link-color-rgb:233, 84, 32;--bs-link-decoration:underline;--bs-link-hover-color:#ba431a;--bs-link-hover-color-rgb:186, 67, 26;--bs-code-color:#e83e8c;--bs-highlight-bg:#fcf1d8;--bs-border-width:1px;--bs-border-style:solid;--bs-border-color:#dee2e6;--bs-border-color-translucent:rgba(0, 0, 0, .175);--bs-border-radius:.375rem;--bs-border-radius-sm:.25rem;--bs-border-radius-lg:.5rem;--bs-border-radius-xl:1rem;--bs-border-radius-xxl:2rem;--bs-border-radius-2xl:var(--bs-border-radius-xxl);--bs-border-radius-pill:50rem;--bs-box-shadow:0 .5rem 1rem rgba(0, 0, 0, .15);--bs-box-shadow-sm:0 .125rem .25rem rgba(0, 0, 0, .075);--bs-box-shadow-lg:0 1rem 3rem rgba(0, 0, 0, .175);--bs-box-shadow-inset:inset 0 1px 2px rgba(0, 0, 0, .075);--bs-focus-ring-width:.25rem;--bs-focus-ring-opacity:.25;--bs-focus-ring-color:rgba(233, 84, 32, .25);--bs-form-valid-color:#38b44a;--bs-form-valid-border-color:#38b44a;--bs-form-invalid-color:#df382c;--bs-form-invalid-border-color:#df382c}*,*:before,*:after{box-sizing:border-box}@media (prefers-reduced-motion: no-preference){:root{scroll-behavior:smooth}}body{margin:0;font-family:var(--bs-body-font-family);font-size:var(--bs-body-font-size);font-weight:var(--bs-body-font-weight);line-height:var(--bs-body-line-height);color:var(--bs-body-color);text-align:var(--bs-body-text-align);background-color:var(--bs-body-bg);-webkit-text-size-adjust:100%;-webkit-tap-highlight-color:rgba(0,0,0,0)}:root{--bs-breakpoint-xs:0;--bs-breakpoint-sm:576px;--bs-breakpoint-md:768px;--bs-breakpoint-lg:992px;--bs-breakpoint-xl:1200px;--bs-breakpoint-xxl:1400px}</style><link rel="stylesheet" href="styles.45b7decdcfaba4f2.css" media="print" onload="this.media='all'"><noscript><link rel="stylesheet" href="styles.45b7decdcfaba4f2.css"></noscript></head>
<body>
<app-root></app-root>
<script src="runtime.7ae29a296d479790.js" type="module"></script><script src="polyfills.7f98574c8bab9a70.js" type="module"></script><script src="main.9c407a6ffadb36e0.js" type="module"></script></body>
<script src="runtime.7ae29a296d479790.js" type="module"></script><script src="polyfills.7f98574c8bab9a70.js" type="module"></script><script src="main.d397ef672ffafd06.js" type="module"></script></body>
</html>

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions client/src/app/_services/message.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { HubConnection, HubConnectionBuilder } from '@microsoft/signalr';
import { User } from '../_models/user';
import { BehaviorSubject, take } from 'rxjs';
import { Group } from '../_models/group';
import { BusyService } from './busy.service';

@Injectable({
providedIn: 'root'
Expand All @@ -18,16 +19,19 @@ export class MessageService {
private messageThreadSouce = new BehaviorSubject<Message[]>([]);
messageThread$ = this.messageThreadSouce.asObservable();

constructor(private http: HttpClient) { }
constructor(private http: HttpClient, private busyService: BusyService) { }

createHubConnection(user: User, otherUsername: string) {
this.busyService.busy();
this.hubConnection = new HubConnectionBuilder()
.withUrl(this.hubUrl + 'message?user=' + otherUsername, {
accessTokenFactory: () => user.token
})
.withAutomaticReconnect()
.build();
this.hubConnection.start().catch(error => console.log(error));
this.hubConnection.start()
.catch(error => console.log(error))
.finally(() => this.busyService.idle());

this.hubConnection.on('ReceiveMessageThread', messages => {
this.messageThreadSouce.next(messages);
Expand Down Expand Up @@ -59,6 +63,7 @@ export class MessageService {

stopHubConnection() {
if (this.hubConnection) {
this.messageThreadSouce.next([]);
this.hubConnection?.stop();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<div class="card">
<div class="card-body">
<div class="card-body"
#scrollMe
style="overflow: scroll; height: 500px;"
[scrollTop]="scrollMe.scrollHeight"
>
<div *ngIf="(messageService.messageThread$ | async)?.length === 0">
No messages yet... say hi by using the message box below
</div>

<ul
#scrollMe
style="overflow: scroll; height: 500px;"
[scrollTop]="scrollMe.scrollHeight"
*ngIf="(messageService.messageThread$ | async)!.length > 0" class="chat">
<li *ngFor="let message of (messageService.messageThread$ | async)">
<div>
Expand Down Expand Up @@ -44,7 +45,9 @@
class="form-control input-sm"
placeholder="Send a private message">
<div class="input-group-append">
<button [disabled]="!messageForm.valid" class="btn btn-primary" type="submit">Send</button>
<button [disabled]="!messageForm.valid || loading" class="btn btn-primary" type="submit">
Send <i *ngIf="loading" class="fa fa-spinner fa-spin"></i>
</button>
</div>
</div>
</form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class MemberMessagesComponent implements OnInit {
@ViewChild('messageForm') messageForm?: NgForm;
@Input() username?: string;
messageContent = '';
loading = false;

constructor(public messageService: MessageService) { }

Expand All @@ -24,9 +25,10 @@ export class MemberMessagesComponent implements OnInit {

sendMessage() {
if (!this.username) return;
this.loading = true;
this.messageService.sendMessage(this.username, this.messageContent).then(() => {
this.messageForm?.reset();
})
}).finally(() => this.loading = false);
}

}

0 comments on commit 1762d03

Please sign in to comment.