Skip to content

Commit ba81d76

Browse files
authored
Merge pull request #4300 from crazyserver/MOBILE-4687
Mobile 4687
2 parents 09bbe3d + eca5bc6 commit ba81d76

File tree

6 files changed

+56
-35
lines changed

6 files changed

+56
-35
lines changed

scripts/langindex.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1558,7 +1558,6 @@
15581558
"core.comments.commentscount": "moodle",
15591559
"core.comments.commentsnotworking": "local_moodlemobileapp",
15601560
"core.comments.deletecommentbyon": "moodle",
1561-
"core.comments.eventcommentcreated": "moodle",
15621561
"core.comments.eventcommentdeleted": "moodle",
15631562
"core.comments.nocomments": "moodle",
15641563
"core.comments.savecomment": "moodle",

src/core/components/combobox/core-combobox.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
<span class="sr-only" *ngIf="label">{{ label }},</span>
1717
<div class="select-text">
18-
<slot name="text">{{selection}}</slot>
18+
<slot name="text"><core-format-text [text]="selection" /></slot>
1919
</div>
2020

2121
<div class="select-icon" role="presentation" aria-hidden="true" slot="end">

src/core/features/comments/lang.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"commentscount": "Comments ({{$a}})",
55
"commentsnotworking": "Comments cannot be retrieved",
66
"deletecommentbyon": "Delete comment posted by {{$a.user}} on {{$a.time}}",
7-
"eventcommentcreated": "Comment created",
87
"eventcommentdeleted": "Comment deleted",
98
"nocomments": "No comments",
109
"savecomment": "Save comment",

src/core/features/comments/pages/viewer/viewer.ts

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
15+
import { Component, OnDestroy, OnInit, ViewChild, AfterViewInit } from '@angular/core';
1616
import { CoreEventObserver, CoreEvents } from '@singletons/events';
1717
import { ActivatedRoute } from '@angular/router';
1818
import { CoreSites } from '@services/sites';
@@ -40,11 +40,12 @@ import { CoreNetwork } from '@services/network';
4040
import moment from 'moment-timezone';
4141
import { Subscription } from 'rxjs';
4242
import { CoreAnimations } from '@components/animations';
43-
import { CoreKeyboard } from '@singletons/keyboard';
4443
import { CoreToasts, ToastDuration } from '@services/overlays/toasts';
4544
import { CoreLoadings } from '@services/overlays/loadings';
4645
import { CORE_COMMENTS_AUTO_SYNCED } from '@features/comments/constants';
4746
import { CoreAlerts } from '@services/overlays/alerts';
47+
import { CoreWait } from '@singletons/wait';
48+
import { CoreDom } from '@singletons/dom';
4849

4950
/**
5051
* Page that displays comments.
@@ -55,7 +56,7 @@ import { CoreAlerts } from '@services/overlays/alerts';
5556
animations: [CoreAnimations.SLIDE_IN_OUT],
5657
styleUrls: ['../../../../../theme/components/discussion.scss', 'viewer.scss'],
5758
})
58-
export class CoreCommentsViewerPage implements OnInit, OnDestroy {
59+
export class CoreCommentsViewerPage implements OnInit, OnDestroy, AfterViewInit {
5960

6061
@ViewChild(IonContent) content?: IonContent;
6162

@@ -86,7 +87,10 @@ export class CoreCommentsViewerPage implements OnInit, OnDestroy {
8687
protected addDeleteCommentsAvailable = false;
8788
protected syncObserver?: CoreEventObserver;
8889
protected onlineObserver: Subscription;
90+
protected keyboardObserver: CoreEventObserver;
8991
protected viewDestroyed = false;
92+
protected scrollBottom = true;
93+
protected scrollElement?: HTMLElement;
9094

9195
constructor(
9296
protected route: ActivatedRoute,
@@ -118,6 +122,11 @@ export class CoreCommentsViewerPage implements OnInit, OnDestroy {
118122
this.isOnline = CoreNetwork.isOnline();
119123
});
120124
});
125+
126+
this.keyboardObserver = CoreEvents.on(CoreEvents.KEYBOARD_CHANGE, (keyboardHeight: number) => {
127+
// Force when opening.
128+
this.scrollToBottom(keyboardHeight > 0);
129+
});
121130
}
122131

123132
/**
@@ -150,6 +159,13 @@ export class CoreCommentsViewerPage implements OnInit, OnDestroy {
150159
await this.fetchComments(true);
151160
}
152161

162+
/**
163+
* View has been initialized.
164+
*/
165+
async ngAfterViewInit(): Promise<void> {
166+
this.scrollElement = await this.content?.getScrollElement();
167+
}
168+
153169
/**
154170
* Fetches the comments.
155171
*
@@ -164,6 +180,8 @@ export class CoreCommentsViewerPage implements OnInit, OnDestroy {
164180
await CorePromiseUtils.ignoreErrors(this.syncComments(showErrors));
165181
}
166182

183+
this.scrollBottom = CoreDom.scrollIsBottom(this.scrollElement, 5);
184+
167185
try {
168186
// Get comments data.
169187
const commentsResponse = await CoreComments.getComments(
@@ -210,9 +228,7 @@ export class CoreCommentsViewerPage implements OnInit, OnDestroy {
210228
this.refreshIcon = CoreConstants.ICON_REFRESH;
211229
this.syncIcon = CoreConstants.ICON_SYNC;
212230

213-
if (this.page == 0) {
214-
this.scrollToBottom();
215-
}
231+
this.scrollToBottom(this.page === 0);
216232
}
217233

218234
}
@@ -314,7 +330,6 @@ export class CoreCommentsViewerPage implements OnInit, OnDestroy {
314330
* @param text Comment text to add.
315331
*/
316332
async addComment(text: string): Promise<void> {
317-
CoreKeyboard.close();
318333
const loadingModal = await CoreLoadings.show('core.sending', true);
319334
// Freeze the add comment button.
320335
this.sending = true;
@@ -328,14 +343,6 @@ export class CoreCommentsViewerPage implements OnInit, OnDestroy {
328343
this.area,
329344
);
330345

331-
CoreToasts.show({
332-
message: commentsResponse ? 'core.comments.eventcommentcreated' : 'core.datastoredoffline',
333-
translateMessage: true,
334-
duration: ToastDuration.LONG,
335-
position: 'bottom',
336-
positionAnchor: 'viewer-footer',
337-
});
338-
339346
if (commentsResponse) {
340347
this.invalidateComments();
341348

@@ -364,11 +371,11 @@ export class CoreCommentsViewerPage implements OnInit, OnDestroy {
364371
} catch (error) {
365372
CoreAlerts.showError(error);
366373
} finally {
367-
loadingModal.dismiss();
368374
this.sending = false;
375+
await loadingModal.dismiss();
369376

370377
// New comments.
371-
this.scrollToBottom();
378+
this.scrollToBottom(true);
372379
}
373380
}
374381

@@ -604,14 +611,25 @@ export class CoreCommentsViewerPage implements OnInit, OnDestroy {
604611

605612
/**
606613
* Scroll bottom when render has finished.
614+
*
615+
* @param force Whether to force scroll to bottom.
607616
*/
608-
protected scrollToBottom(): void {
609-
// Need a timeout to leave time to the view to be rendered.
610-
setTimeout(() => {
611-
if (!this.viewDestroyed) {
612-
this.content?.scrollToBottom();
613-
}
614-
}, 100);
617+
protected async scrollToBottom(force = false): Promise<void> {
618+
if (this.viewDestroyed) {
619+
return;
620+
}
621+
622+
// Check if scroll is at bottom. If so, scroll bottom after rendering since there might be something new.
623+
if (!this.scrollBottom && !force) {
624+
return;
625+
}
626+
627+
// Leave time for the view to be rendered.
628+
await CoreWait.nextTicks(5);
629+
630+
if (!this.viewDestroyed && this.content) {
631+
this.content.scrollToBottom(0);
632+
}
615633
}
616634

617635
/**
@@ -650,6 +668,7 @@ export class CoreCommentsViewerPage implements OnInit, OnDestroy {
650668
this.syncObserver?.off();
651669
this.onlineObserver.unsubscribe();
652670
this.viewDestroyed = true;
671+
this.keyboardObserver.off();
653672
}
654673

655674
}

src/core/features/comments/tests/behat/basic_usage.feature

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ Feature: Test basic usage of comments in app
3838
And I press "Comments (0)" in the app
3939
And I set the field "Add a comment..." to "comment test teacher" in the app
4040
And I press "Send" in the app
41-
Then I should find "Comment created" in the app
4241
And I should find "comment test teacher" in the app
42+
And I should not find "There are offline comments to be synchronised" in the app
4343

4444
When I go back in the app
4545
And I should find "Comments (1)" in the app
@@ -51,9 +51,9 @@ Feature: Test basic usage of comments in app
5151
And I press "Comments (1)" in the app
5252
And I set the field "Add a comment..." to "comment test student" in the app
5353
And I press "Send" in the app
54-
Then I should find "Comment created" in the app
5554
And I should find "comment test teacher" in the app
5655
And I should find "comment test student" in the app
56+
And I should not find "There are offline comments to be synchronised" in the app
5757

5858
When I go back in the app
5959
And I press "Comments (2)" in the app
@@ -78,7 +78,6 @@ Feature: Test basic usage of comments in app
7878
And I switch network connection to offline
7979
And I set the field "Add a comment..." to "comment test" in the app
8080
And I press "Send" in the app
81-
Then I should find "Data stored in the device because it couldn't be sent. It will be sent automatically later." in the app
8281
And I should find "There are offline comments to be synchronised." in the app
8382
And I should find "comment test" in the app
8483

@@ -126,8 +125,8 @@ Feature: Test basic usage of comments in app
126125
And I press "Comments (0)" in the app
127126
And I set the field "Add a comment..." to "comment test teacher" in the app
128127
And I press "Send" in the app
129-
Then I should find "Comment created" in the app
130128
And I should find "comment test teacher" in the app
129+
And I should not find "There are offline comments to be synchronised" in the app
131130
And I go back in the app
132131
And I should find "Comments (1)" in the app
133132

@@ -138,9 +137,9 @@ Feature: Test basic usage of comments in app
138137
And I press "Comments (1)" in the app
139138
And I set the field "Add a comment..." to "comment test student" in the app
140139
And I press "Send" in the app
141-
Then I should find "Comment created" in the app
142140
And I should find "comment test teacher" in the app
143141
And I should find "comment test student" in the app
142+
And I should not find "There are offline comments to be synchronised" in the app
144143

145144
When I go back in the app
146145
And I press "Comments (2)" in the app
@@ -166,7 +165,6 @@ Feature: Test basic usage of comments in app
166165
And I switch network connection to offline
167166
And I set the field "Add a comment..." to "comment test" in the app
168167
And I press "Send" in the app
169-
Then I should find "Data stored in the device because it couldn't be sent. It will be sent automatically later." in the app
170168
And I should find "There are offline comments to be synchronised." in the app
171169
And I should find "comment test" in the app
172170

@@ -218,8 +216,8 @@ Feature: Test basic usage of comments in app
218216
When I press "Comments (0)" in the app
219217
And I set the field "Add a comment..." to "comment test" in the app
220218
And I press "Send" in the app
221-
Then I should find "Comment created" in the app
222219
And I should find "comment test" in the app
220+
And I should not find "There are offline comments to be synchronised" in the app
223221

224222
When I go back in the app
225223
And I press "Comments (1)" in the app
@@ -249,7 +247,6 @@ Feature: Test basic usage of comments in app
249247
And I switch network connection to offline
250248
And I set the field "Add a comment..." to "comment test" in the app
251249
And I press "Send" in the app
252-
Then I should find "Data stored in the device because it couldn't be sent. It will be sent automatically later." in the app
253250
And I should find "There are offline comments to be synchronised." in the app
254251
And I should find "comment test" in the app
255252

src/core/features/sitehome/pages/index/index.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,11 @@ section.core-course-module-list-wrapper {
2727
core-course-module.core-sitehome-news {
2828
--card-border-width: var(--ion-card-border-width);
2929
--card-radius: var(--ion-card-radius);
30+
::ng-deep ion-card {
31+
padding-top: 4px !important;
32+
--card-padding-bottom: 4px;
33+
ion-item {
34+
--padding-start: 16px;
35+
}
36+
}
3037
}

0 commit comments

Comments
 (0)