MOBILE-3926 core: Simplify swipe implementation
parent
57532fd393
commit
c041e2a314
|
@ -33,10 +33,10 @@ export class AddonBadgesUserBadgesSource extends CoreItemsManagerSource<AddonBad
|
|||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected async loadPageItems(): Promise<{ items: AddonBadgesUserBadge[]; hasMoreItems: boolean }> {
|
||||
protected async loadPageItems(): Promise<{ items: AddonBadgesUserBadge[] }> {
|
||||
const badges = await AddonBadges.getUserBadges(this.COURSE_ID, this.USER_ID);
|
||||
|
||||
return { items: badges, hasMoreItems: false };
|
||||
return { items: badges };
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -143,11 +143,7 @@ class AddonBadgesUserBadgesSwipeManager extends CoreSwipeItemsManager<AddonBadge
|
|||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected getSelectedItemPath(route?: ActivatedRouteSnapshot | null): string | null {
|
||||
if (!route) {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected getSelectedItemPathFromRoute(route: ActivatedRouteSnapshot): string | null {
|
||||
return route.params.badgeHash;
|
||||
}
|
||||
|
||||
|
|
|
@ -127,7 +127,7 @@ export abstract class CoreItemsManagerSource<Item = unknown> {
|
|||
async reload(): Promise<void> {
|
||||
const { items, hasMoreItems } = await this.loadPageItems(0);
|
||||
|
||||
this.setItems(items, hasMoreItems);
|
||||
this.setItems(items, hasMoreItems ?? false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -140,7 +140,7 @@ export abstract class CoreItemsManagerSource<Item = unknown> {
|
|||
|
||||
const { items, hasMoreItems } = await this.loadPageItems(this.getPagesLoaded());
|
||||
|
||||
this.setItems((this.items ?? []).concat(items), hasMoreItems);
|
||||
this.setItems((this.items ?? []).concat(items), hasMoreItems ?? false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -149,7 +149,7 @@ export abstract class CoreItemsManagerSource<Item = unknown> {
|
|||
* @param page Page number (starting at 0).
|
||||
* @return Page items data.
|
||||
*/
|
||||
protected abstract loadPageItems(page: number): Promise<{ items: Item[]; hasMoreItems: boolean }>;
|
||||
protected abstract loadPageItems(page: number): Promise<{ items: Item[]; hasMoreItems?: boolean }>;
|
||||
|
||||
/**
|
||||
* Get the length of each page in the collection.
|
||||
|
|
|
@ -101,10 +101,10 @@ export abstract class CoreItemsManager<Item = unknown, Source extends CoreItemsM
|
|||
protected abstract getItemPath(item: Item): string;
|
||||
|
||||
/**
|
||||
* Get the path of the selected item given the current route.
|
||||
* Get the path of the selected item.
|
||||
*
|
||||
* @param route Page route.
|
||||
* @return Path of the selected item in the given route.
|
||||
* @param route Page route, if any.
|
||||
* @return Path of the selected item.
|
||||
*/
|
||||
protected abstract getSelectedItemPath(route?: ActivatedRouteSnapshot | null): string | null;
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { ActivatedRoute, ActivatedRouteSnapshot } from '@angular/router';
|
||||
|
||||
import { CoreNavigator } from '@services/navigator';
|
||||
|
||||
|
@ -49,6 +49,14 @@ export abstract class CoreSwipeItemsManager<
|
|||
await this.navigateToItemBy(1, 'forward');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path of the selected item given the current route.
|
||||
*
|
||||
* @param route Page route.
|
||||
* @return Path of the selected item in the given route.
|
||||
*/
|
||||
protected abstract getSelectedItemPathFromRoute(route: ActivatedRouteSnapshot): string | null;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
|
@ -56,6 +64,17 @@ export abstract class CoreSwipeItemsManager<
|
|||
return CoreNavigator.getCurrentRoute();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected getSelectedItemPath(route?: ActivatedRouteSnapshot | null): string | null {
|
||||
if (!route) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.getSelectedItemPathFromRoute(route);
|
||||
}
|
||||
|
||||
/**
|
||||
* Navigate to an item by an offset.
|
||||
*
|
||||
|
|
|
@ -254,11 +254,7 @@ class CoreUserSwipeItemsManager extends CoreSwipeItemsManager<CoreUserBasicData>
|
|||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected getSelectedItemPath(route?: ActivatedRouteSnapshot | null): string | null {
|
||||
if (!route) {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected getSelectedItemPathFromRoute(route: ActivatedRouteSnapshot): string | null {
|
||||
return route.params.userId;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue