Skip to content

Commit

Permalink
Merge pull request #4300 from crazyserver/MOBILE-4687
Browse files Browse the repository at this point in the history
Mobile 4687
  • Loading branch information
dpalou authored Jan 29, 2025
2 parents 09bbe3d + eca5bc6 commit ba81d76
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 35 deletions.
1 change: 0 additions & 1 deletion scripts/langindex.json
Original file line number Diff line number Diff line change
Expand Up @@ -1558,7 +1558,6 @@
"core.comments.commentscount": "moodle",
"core.comments.commentsnotworking": "local_moodlemobileapp",
"core.comments.deletecommentbyon": "moodle",
"core.comments.eventcommentcreated": "moodle",
"core.comments.eventcommentdeleted": "moodle",
"core.comments.nocomments": "moodle",
"core.comments.savecomment": "moodle",
Expand Down
2 changes: 1 addition & 1 deletion src/core/components/combobox/core-combobox.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

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

<div class="select-icon" role="presentation" aria-hidden="true" slot="end">
Expand Down
1 change: 0 additions & 1 deletion src/core/features/comments/lang.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"commentscount": "Comments ({{$a}})",
"commentsnotworking": "Comments cannot be retrieved",
"deletecommentbyon": "Delete comment posted by {{$a.user}} on {{$a.time}}",
"eventcommentcreated": "Comment created",
"eventcommentdeleted": "Comment deleted",
"nocomments": "No comments",
"savecomment": "Save comment",
Expand Down
67 changes: 43 additions & 24 deletions src/core/features/comments/pages/viewer/viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { Component, OnDestroy, OnInit, ViewChild, AfterViewInit } from '@angular/core';
import { CoreEventObserver, CoreEvents } from '@singletons/events';
import { ActivatedRoute } from '@angular/router';
import { CoreSites } from '@services/sites';
Expand Down Expand Up @@ -40,11 +40,12 @@ import { CoreNetwork } from '@services/network';
import moment from 'moment-timezone';
import { Subscription } from 'rxjs';
import { CoreAnimations } from '@components/animations';
import { CoreKeyboard } from '@singletons/keyboard';
import { CoreToasts, ToastDuration } from '@services/overlays/toasts';
import { CoreLoadings } from '@services/overlays/loadings';
import { CORE_COMMENTS_AUTO_SYNCED } from '@features/comments/constants';
import { CoreAlerts } from '@services/overlays/alerts';
import { CoreWait } from '@singletons/wait';
import { CoreDom } from '@singletons/dom';

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

@ViewChild(IonContent) content?: IonContent;

Expand Down Expand Up @@ -86,7 +87,10 @@ export class CoreCommentsViewerPage implements OnInit, OnDestroy {
protected addDeleteCommentsAvailable = false;
protected syncObserver?: CoreEventObserver;
protected onlineObserver: Subscription;
protected keyboardObserver: CoreEventObserver;
protected viewDestroyed = false;
protected scrollBottom = true;
protected scrollElement?: HTMLElement;

constructor(
protected route: ActivatedRoute,
Expand Down Expand Up @@ -118,6 +122,11 @@ export class CoreCommentsViewerPage implements OnInit, OnDestroy {
this.isOnline = CoreNetwork.isOnline();
});
});

this.keyboardObserver = CoreEvents.on(CoreEvents.KEYBOARD_CHANGE, (keyboardHeight: number) => {
// Force when opening.
this.scrollToBottom(keyboardHeight > 0);
});
}

/**
Expand Down Expand Up @@ -150,6 +159,13 @@ export class CoreCommentsViewerPage implements OnInit, OnDestroy {
await this.fetchComments(true);
}

/**
* View has been initialized.
*/
async ngAfterViewInit(): Promise<void> {
this.scrollElement = await this.content?.getScrollElement();
}

/**
* Fetches the comments.
*
Expand All @@ -164,6 +180,8 @@ export class CoreCommentsViewerPage implements OnInit, OnDestroy {
await CorePromiseUtils.ignoreErrors(this.syncComments(showErrors));
}

this.scrollBottom = CoreDom.scrollIsBottom(this.scrollElement, 5);

try {
// Get comments data.
const commentsResponse = await CoreComments.getComments(
Expand Down Expand Up @@ -210,9 +228,7 @@ export class CoreCommentsViewerPage implements OnInit, OnDestroy {
this.refreshIcon = CoreConstants.ICON_REFRESH;
this.syncIcon = CoreConstants.ICON_SYNC;

if (this.page == 0) {
this.scrollToBottom();
}
this.scrollToBottom(this.page === 0);
}

}
Expand Down Expand Up @@ -314,7 +330,6 @@ export class CoreCommentsViewerPage implements OnInit, OnDestroy {
* @param text Comment text to add.
*/
async addComment(text: string): Promise<void> {
CoreKeyboard.close();
const loadingModal = await CoreLoadings.show('core.sending', true);
// Freeze the add comment button.
this.sending = true;
Expand All @@ -328,14 +343,6 @@ export class CoreCommentsViewerPage implements OnInit, OnDestroy {
this.area,
);

CoreToasts.show({
message: commentsResponse ? 'core.comments.eventcommentcreated' : 'core.datastoredoffline',
translateMessage: true,
duration: ToastDuration.LONG,
position: 'bottom',
positionAnchor: 'viewer-footer',
});

if (commentsResponse) {
this.invalidateComments();

Expand Down Expand Up @@ -364,11 +371,11 @@ export class CoreCommentsViewerPage implements OnInit, OnDestroy {
} catch (error) {
CoreAlerts.showError(error);
} finally {
loadingModal.dismiss();
this.sending = false;
await loadingModal.dismiss();

// New comments.
this.scrollToBottom();
this.scrollToBottom(true);
}
}

Expand Down Expand Up @@ -604,14 +611,25 @@ export class CoreCommentsViewerPage implements OnInit, OnDestroy {

/**
* Scroll bottom when render has finished.
*
* @param force Whether to force scroll to bottom.
*/
protected scrollToBottom(): void {
// Need a timeout to leave time to the view to be rendered.
setTimeout(() => {
if (!this.viewDestroyed) {
this.content?.scrollToBottom();
}
}, 100);
protected async scrollToBottom(force = false): Promise<void> {
if (this.viewDestroyed) {
return;
}

// Check if scroll is at bottom. If so, scroll bottom after rendering since there might be something new.
if (!this.scrollBottom && !force) {
return;
}

// Leave time for the view to be rendered.
await CoreWait.nextTicks(5);

if (!this.viewDestroyed && this.content) {
this.content.scrollToBottom(0);
}
}

/**
Expand Down Expand Up @@ -650,6 +668,7 @@ export class CoreCommentsViewerPage implements OnInit, OnDestroy {
this.syncObserver?.off();
this.onlineObserver.unsubscribe();
this.viewDestroyed = true;
this.keyboardObserver.off();
}

}
Expand Down
13 changes: 5 additions & 8 deletions src/core/features/comments/tests/behat/basic_usage.feature
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ Feature: Test basic usage of comments in app
And I press "Comments (0)" in the app
And I set the field "Add a comment..." to "comment test teacher" in the app
And I press "Send" in the app
Then I should find "Comment created" in the app
And I should find "comment test teacher" in the app
And I should not find "There are offline comments to be synchronised" in the app

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

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

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

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

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

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

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

Expand Down
7 changes: 7 additions & 0 deletions src/core/features/sitehome/pages/index/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,11 @@ section.core-course-module-list-wrapper {
core-course-module.core-sitehome-news {
--card-border-width: var(--ion-card-border-width);
--card-radius: var(--ion-card-radius);
::ng-deep ion-card {
padding-top: 4px !important;
--card-padding-bottom: 4px;
ion-item {
--padding-start: 16px;
}
}
}

0 comments on commit ba81d76

Please sign in to comment.