-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for http file upload
- Loading branch information
Showing
16 changed files
with
227 additions
and
24 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
projects/pazznetwork/ngx-chat/src/lib/components/chat-filedrop/file-drop.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<div> | ||
<div class="drop-message" | ||
[class.drop-message--visible]="isDropTarget"> | ||
{{dropMessage}} | ||
</div> | ||
<div> | ||
<ng-content></ng-content> | ||
</div> | ||
</div> |
23 changes: 23 additions & 0 deletions
23
projects/pazznetwork/ngx-chat/src/lib/components/chat-filedrop/file-drop.component.less
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
.drop-message { | ||
pointer-events: none; | ||
display: none; | ||
} | ||
|
||
.drop-message--visible { | ||
position: absolute; | ||
top: 0; | ||
bottom: 0; | ||
left: 0; | ||
right: 0; | ||
|
||
display: flex; | ||
justify-content: center; | ||
align-content: center; | ||
flex-direction: column; | ||
|
||
text-align: center; | ||
font-size: 1.5em; | ||
z-index: 999; | ||
background-color: rgba(255, 255, 255, 0.6); | ||
padding: 1em; | ||
} |
54 changes: 54 additions & 0 deletions
54
projects/pazznetwork/ngx-chat/src/lib/components/chat-filedrop/file-drop.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { Component, EventEmitter, HostListener, Input, OnInit, Output } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'ngx-chat-filedrop', | ||
templateUrl: './file-drop.component.html', | ||
styleUrls: ['./file-drop.component.less'] | ||
}) | ||
export class FileDropComponent implements OnInit { | ||
|
||
@Output() | ||
public fileUpload = new EventEmitter<File>(); | ||
|
||
@Input() | ||
dropMessage: string; | ||
|
||
isDropTarget = false; | ||
|
||
constructor() { } | ||
|
||
ngOnInit() { | ||
} | ||
|
||
@HostListener('dragover', ['$event']) | ||
@HostListener('dragenter', ['$event']) | ||
onDragOver(event: DragEvent) { | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
this.isDropTarget = true; | ||
} | ||
|
||
@HostListener('dragleave', ['$event']) | ||
@HostListener('dragexit', ['$event']) | ||
onDragLeave(event: DragEvent) { | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
this.isDropTarget = false; | ||
} | ||
|
||
@HostListener('drop', ['$event']) | ||
async onDrop(event: DragEvent) { | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
|
||
this.isDropTarget = false; | ||
|
||
for (let i = 0; i < event.dataTransfer.items.length; i++) { | ||
const dataTransferItem = event.dataTransfer.items[i]; | ||
if (dataTransferItem.kind === 'file') { | ||
this.fileUpload.emit(dataTransferItem.getAsFile()); | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
min-height: 10em; | ||
max-height: 20em; | ||
overflow: scroll; | ||
word-break: break-all; | ||
} | ||
|
||
.chat-messages-empty { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
...znetwork/ngx-chat/src/lib/components/chat-room-messages/chat-room-messages.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 17 additions & 15 deletions
32
projects/pazznetwork/ngx-chat/src/lib/components/chat-window/chat-window.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,23 @@ | ||
<div class="chat-window"> | ||
<div (click)="onClickHeader()" class="chat-contact-header" [title]="chatWindowState.contact.name"> | ||
<div class="chat-contact-avatar"> | ||
<img [src]="chatWindowState.contact.avatar"/> | ||
<ngx-chat-filedrop (fileUpload)="onFileUpload($event)" [dropMessage]="chatService.translations.dropMessage"> | ||
<div (click)="onClickHeader()" class="chat-contact-header" [title]="chatWindowState.contact.name"> | ||
<div class="chat-contact-avatar"> | ||
<img [src]="chatWindowState.contact.avatar"/> | ||
</div> | ||
<div class="chat-contact-name"> | ||
{{chatWindowState.contact.name}} | ||
</div> | ||
<div class="chat-close" (click)="onClickClose()"> | ||
× | ||
</div> | ||
</div> | ||
<div class="chat-contact-name"> | ||
{{chatWindowState.contact.name}} | ||
</div> | ||
<div class="chat-close" (click)="onClickClose()"> | ||
× | ||
</div> | ||
</div> | ||
<div *ngIf="!chatWindowState.isCollapsed" class="chat-content"> | ||
<div *ngIf="!chatWindowState.isCollapsed" class="chat-content"> | ||
|
||
<ngx-chat-message-list [contact]="chatWindowState.contact" [showAvatars]="false"></ngx-chat-message-list> | ||
<ngx-chat-message-list [contact]="chatWindowState.contact" [showAvatars]="false"></ngx-chat-message-list> | ||
|
||
<div class="chat-input-container"> | ||
<ngx-chat-message-input [contact]="chatWindowState.contact"></ngx-chat-message-input> | ||
<div class="chat-input-container"> | ||
<ngx-chat-message-input [contact]="chatWindowState.contact"></ngx-chat-message-input> | ||
</div> | ||
</div> | ||
</div> | ||
</ngx-chat-filedrop> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,5 @@ export interface Translations { | |
timeFormat: string; | ||
dateFormat: string; | ||
locale: string; | ||
dropMessage: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const urlRegex = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim; | ||
|
||
export function extractUrls(message: string) { | ||
return message.match(urlRegex) || []; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.