Skip to content

Commit

Permalink
Fix 2 noti when change language
Browse files Browse the repository at this point in the history
  • Loading branch information
HeidiTran committed Jul 31, 2020
2 parents 3039c64 + 45f811e commit 2576f96
Show file tree
Hide file tree
Showing 8 changed files with 302 additions and 222 deletions.
File renamed without changes.
23 changes: 23 additions & 0 deletions Docs/Todo list 30-7.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Todo list:
1/ Giang:
- Fix icon menu
- Tự động tải backup file khi đứt wifi
- Làm zen mode (full screen)
- Tao nghĩ contact form submit xong nên cho alertify success (Thay vì THANK YOU)
- Mày có muốn làm cái Custom Undo stack ko, khá thú vị
- Protect C# database = token authentification hay gì đó (Hiện tại gõ đúng link lên browser là xóa đc peer, tạo đc room,...)


2/ Minh:
- Nghĩ cách giải thích CRDT
- Research vụ deploy domain name của mình có forward đc ko
- Clean nốt code
- Làm cursor, select effect giống google docs
- Lưu code trên server


3/ Other interesting stuff:
- Instruction có animation giống trong game (Giang nhé :)) )
- Make sync Ctrl-D shortcut works (Probably Minh)
- Đứt wifi thì try to reconnect trước đã, ko đc thì mới crash
- Làm video call
10 changes: 5 additions & 5 deletions code-spot-client/src/app/code-editor/code-editor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class CodeEditorComponent implements OnInit {
selectedTheme: string;
editorForm = new FormGroup({
language: new FormControl(
EditorService.language,
EditorService.currentLanguage,
Validators.compose([Validators.required])
),
theme: new FormControl(
Expand All @@ -61,21 +61,21 @@ export class CodeEditorComponent implements OnInit {
}

ngOnInit() {
this.selectedLang = EditorService.language;
this.selectedLang = EditorService.currentLanguage;
this.selectedTheme = 'vs-dark';
}

editorOptions = {
theme: 'vs-dark',
language: EditorService.language,
language: EditorService.currentLanguage,
wordWrap: 'on',
trimAutoWhitespace: false,
};

onLanguageChange(res: string) {
this.selectedLang = res.slice(res.indexOf(':') + 2);
monaco.editor.setModelLanguage(this.editorTextModel, this.selectedLang);
EditorService.language = this.selectedLang;
EditorService.currentLanguage = this.selectedLang;
this.peerService.broadcastChangeLanguage();
}

Expand Down Expand Up @@ -263,7 +263,7 @@ export class CodeEditorComponent implements OnInit {
this.location.replaceState('/editor/' + this.roomName);
break;
case AnnounceType.ChangeLanguage:
this.selectedLang = EditorService.language;
this.selectedLang = EditorService.currentLanguage;
monaco.editor.setModelLanguage(
this.editorTextModel,
this.selectedLang
Expand Down
27 changes: 26 additions & 1 deletion code-spot-client/src/app/services/broadcast.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ export class BroadcastService {
conn.send(message);
}

/**
* Send old chat messages, old crdts and most recent change language
*/
sendOldData(conn: any, oldChatMessages: Message[], oldCRDTs: CRDT[]) {
this.sendOldCRDTs(conn, oldCRDTs);
this.sendOldMessages(conn, oldChatMessages);
this.sendChangeLanguage(conn);
}

sendMyCursorColor(conn: any, myColor: number) {
conn.send(new Message(myColor + '', MessageType.CursorColor, this.peer.id));
}
Expand Down Expand Up @@ -152,7 +161,7 @@ export class BroadcastService {

sendChangeLanguage(conn: any) {
const messageToSend = new Message(
EditorService.language,
EditorService.currentLanguage,
MessageType.ChangeLanguage,
this.peer.id
);
Expand Down Expand Up @@ -204,6 +213,12 @@ export class BroadcastService {
conn.send(message);
}

sendNameAndCursorInfo(conn: any, name: string): void {
// Order is important! Name first and then cursor info!
this.sendMyName(conn, name);
this.sendCursorInfo(conn);
}

/**
* Send our cursor color, cursor pos and selection pos
*/
Expand All @@ -226,6 +241,16 @@ export class BroadcastService {
conn.send(message);
}

tellPeerCannotSendOldData(conn: any) {
conn.send(
new Message(
null,
MessageType.CannotSendOldCRDTsOrOldChatMessages,
this.peer.id
)
);
}

/**
* Get our peer object from peerService
*/
Expand Down
2 changes: 1 addition & 1 deletion code-spot-client/src/app/services/cursor.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export class CursorService {
}

// Recalculate my nameTag index
const myNewIndex = this.nameTagIndexAfterInsert(
const myNewIndex = this.nameTagIndexAfterRemove(
this.myNameTagIndex,
removeStartIndex,
removeLength
Expand Down
3 changes: 2 additions & 1 deletion code-spot-client/src/app/services/editor.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { CursorChangeInfo } from '../shared/CursorChangeInfo';
providedIn: 'root',
})
export class EditorService {
static language: string = 'cpp';
static defaultLanguage: string = 'cpp';
static currentLanguage: string = EditorService.defaultLanguage;
static siteId: number = -1;
static remoteOpLeft: number = 0;
curClock: number = 0;
Expand Down
Loading

0 comments on commit 2576f96

Please sign in to comment.