From 3bb2af6088b08d8c57ac2fcc1320125eeff1d5ca Mon Sep 17 00:00:00 2001 From: mkovalua Date: Wed, 3 Dec 2025 21:01:50 +0200 Subject: [PATCH 1/4] load project files on scrolling on preprint creation --- .../stepper/file-step/file-step.component.html | 2 ++ .../stepper/file-step/file-step.component.ts | 8 ++++++-- .../preprint-stepper.actions.ts | 5 ++++- .../preprint-stepper/preprint-stepper.state.ts | 17 +++++++++++++---- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/app/features/preprints/components/stepper/file-step/file-step.component.html b/src/app/features/preprints/components/stepper/file-step/file-step.component.html index d52b9043b..aa2f3fc05 100644 --- a/src/app/features/preprints/components/stepper/file-step/file-step.component.html +++ b/src/app/features/preprints/components/stepper/file-step/file-step.component.html @@ -97,8 +97,10 @@

{{ 'preprints.preprintStepper.file.title' | translate }}

[selectionMode]="null" [isLoading]="areProjectFilesLoading() || isCurrentFolderLoading()" [resourceId]="selectedProjectId()!" + [scrollHeight]="'400px'" (entryFileClicked)="selectProjectFile($event)" (setCurrentFolder)="setCurrentFolder($event)" + (loadFiles)="onLoadFiles($event)" /> } diff --git a/src/app/features/preprints/components/stepper/file-step/file-step.component.ts b/src/app/features/preprints/components/stepper/file-step/file-step.component.ts index 99b5601fd..d60032bd2 100644 --- a/src/app/features/preprints/components/stepper/file-step/file-step.component.ts +++ b/src/app/features/preprints/components/stepper/file-step/file-step.component.ts @@ -190,7 +190,7 @@ export class FileStepComponent implements OnInit { switchMap(() => { const filesLink = this.currentFolder()?.links.filesLink; if (filesLink) { - return this.actions.getProjectFilesByLink(filesLink); + return this.actions.getProjectFilesByLink(filesLink, 1); } else { return EMPTY; } @@ -232,6 +232,10 @@ export class FileStepComponent implements OnInit { return; } this.actions.setCurrentFolder(folder); - this.actions.getProjectFilesByLink(folder.links.filesLink); + this.actions.getProjectFilesByLink(folder.links.filesLink, 1); + } + + onLoadFiles(event: { link: string; page: number }) { + this.actions.getProjectFilesByLink(event.link, event.page); } } diff --git a/src/app/features/preprints/store/preprint-stepper/preprint-stepper.actions.ts b/src/app/features/preprints/store/preprint-stepper/preprint-stepper.actions.ts index d4bef602e..23d62a456 100644 --- a/src/app/features/preprints/store/preprint-stepper/preprint-stepper.actions.ts +++ b/src/app/features/preprints/store/preprint-stepper/preprint-stepper.actions.ts @@ -90,7 +90,10 @@ export class SetProjectRootFolder { export class FetchProjectFilesByLink { static readonly type = '[Preprint Stepper] Get Project Files By Link'; - constructor(public filesLink: string) {} + constructor( + public filesLink: string, + public page: number + ) {} } export class FetchLicenses { diff --git a/src/app/features/preprints/store/preprint-stepper/preprint-stepper.state.ts b/src/app/features/preprints/store/preprint-stepper/preprint-stepper.state.ts index 21c685ccd..9bbbfcb6b 100644 --- a/src/app/features/preprints/store/preprint-stepper/preprint-stepper.state.ts +++ b/src/app/features/preprints/store/preprint-stepper/preprint-stepper.state.ts @@ -255,14 +255,23 @@ export class PreprintStepperState { @Action(FetchProjectFilesByLink) getProjectFilesByLink(ctx: StateContext, action: FetchProjectFilesByLink) { - ctx.setState(patch({ projectFiles: patch({ isLoading: true }) })); - - return this.fileService.getFilesWithoutFiltering(action.filesLink, 1).pipe( + // getProjectFilesByLink(ctx: StateContext, action: FetchProjectFilesByLink { filesLink, page }: GetFiles) { + // ctx.setState(patch({ projectFiles: patch({ isLoading: true }) })); + const state = ctx.getState(); + ctx.patchState({ + projectFiles: { + ...state.projectFiles, + isLoading: true, + }, + }); + alert('getProjectFilesByLink'); + return this.fileService.getFilesWithoutFiltering(action.filesLink, action.page).pipe( tap((response) => { + const newData = action.page === 1 ? response.data : [...(state.projectFiles.data ?? []), ...response.data]; ctx.setState( patch({ projectFiles: patch({ - data: response.data, + data: newData, isLoading: false, }), }) From 13e866fff5e694807fe560a4627204eee3d785e5 Mon Sep 17 00:00:00 2001 From: mkovalua Date: Thu, 4 Dec 2025 12:33:27 +0200 Subject: [PATCH 2/4] accumulate project files on scrolling for preprint creation --- .../file-step/file-step.component.html | 4 ++-- .../stepper/file-step/file-step.component.ts | 1 + .../preprint-stepper.model.ts | 4 +++- .../preprint-stepper.selectors.ts | 6 ++++++ .../preprint-stepper.state.ts | 19 ++++++++----------- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/app/features/preprints/components/stepper/file-step/file-step.component.html b/src/app/features/preprints/components/stepper/file-step/file-step.component.html index aa2f3fc05..8a95bdcec 100644 --- a/src/app/features/preprints/components/stepper/file-step/file-step.component.html +++ b/src/app/features/preprints/components/stepper/file-step/file-step.component.html @@ -92,12 +92,12 @@

{{ 'preprints.preprintStepper.file.title' | translate }}

; preprintFile: AsyncStateModel; availableProjects: AsyncStateModel; - projectFiles: AsyncStateModel; + projectFiles: AsyncStateWithTotalCount; licenses: AsyncStateModel; currentFolder: AsyncStateModel; preprintProject: AsyncStateModel; @@ -51,6 +52,7 @@ export const DEFAULT_PREPRINT_STEPPER_STATE: PreprintStepperStateModel = { data: [], isLoading: false, error: null, + totalCount: 0, }, licenses: { data: [], diff --git a/src/app/features/preprints/store/preprint-stepper/preprint-stepper.selectors.ts b/src/app/features/preprints/store/preprint-stepper/preprint-stepper.selectors.ts index 96524b08e..182b4402e 100644 --- a/src/app/features/preprints/store/preprint-stepper/preprint-stepper.selectors.ts +++ b/src/app/features/preprints/store/preprint-stepper/preprint-stepper.selectors.ts @@ -53,6 +53,12 @@ export class PreprintStepperSelectors { return state.projectFiles.data; } + @Selector([PreprintStepperState]) + static getFilesTotalCount(state: PreprintStepperStateModel) { + alert(state.projectFiles.totalCount); + return state.projectFiles.totalCount; + } + @Selector([PreprintStepperState]) static areProjectFilesLoading(state: PreprintStepperStateModel) { return state.projectFiles.isLoading; diff --git a/src/app/features/preprints/store/preprint-stepper/preprint-stepper.state.ts b/src/app/features/preprints/store/preprint-stepper/preprint-stepper.state.ts index 9bbbfcb6b..b3b3559f8 100644 --- a/src/app/features/preprints/store/preprint-stepper/preprint-stepper.state.ts +++ b/src/app/features/preprints/store/preprint-stepper/preprint-stepper.state.ts @@ -255,8 +255,6 @@ export class PreprintStepperState { @Action(FetchProjectFilesByLink) getProjectFilesByLink(ctx: StateContext, action: FetchProjectFilesByLink) { - // getProjectFilesByLink(ctx: StateContext, action: FetchProjectFilesByLink { filesLink, page }: GetFiles) { - // ctx.setState(patch({ projectFiles: patch({ isLoading: true }) })); const state = ctx.getState(); ctx.patchState({ projectFiles: { @@ -264,18 +262,17 @@ export class PreprintStepperState { isLoading: true, }, }); - alert('getProjectFilesByLink'); return this.fileService.getFilesWithoutFiltering(action.filesLink, action.page).pipe( tap((response) => { const newData = action.page === 1 ? response.data : [...(state.projectFiles.data ?? []), ...response.data]; - ctx.setState( - patch({ - projectFiles: patch({ - data: newData, - isLoading: false, - }), - }) - ); + ctx.patchState({ + projectFiles: { + data: newData, + isLoading: false, + totalCount: response.totalCount, + error: null, + }, + }); }), catchError((error) => handleSectionError(ctx, 'projectFiles', error)) ); From 38c125bb82569d90625db72bc0131efe4d5b04d1 Mon Sep 17 00:00:00 2001 From: mkovalua Date: Thu, 4 Dec 2025 12:39:50 +0200 Subject: [PATCH 3/4] remove redundant alert --- .../store/preprint-stepper/preprint-stepper.selectors.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/app/features/preprints/store/preprint-stepper/preprint-stepper.selectors.ts b/src/app/features/preprints/store/preprint-stepper/preprint-stepper.selectors.ts index 182b4402e..314b21f12 100644 --- a/src/app/features/preprints/store/preprint-stepper/preprint-stepper.selectors.ts +++ b/src/app/features/preprints/store/preprint-stepper/preprint-stepper.selectors.ts @@ -1,6 +1,6 @@ import { Selector } from '@ngxs/store'; -import { PreprintStepperState, PreprintStepperStateModel } from '@osf/features/preprints/store/preprint-stepper'; +import { PreprintStepperState, PreprintStepperStateModel } from '@osf/features/preprints/store/preprint-stepper' export class PreprintStepperSelectors { @Selector([PreprintStepperState]) @@ -55,7 +55,6 @@ export class PreprintStepperSelectors { @Selector([PreprintStepperState]) static getFilesTotalCount(state: PreprintStepperStateModel) { - alert(state.projectFiles.totalCount); return state.projectFiles.totalCount; } From 389bf4f0c984bcf8fdbff633465381b2c11bdec5 Mon Sep 17 00:00:00 2001 From: mkovalua Date: Thu, 4 Dec 2025 15:58:10 +0200 Subject: [PATCH 4/4] fix encoding & < > issues and linter issues --- .../preprints/services/preprints-projects.service.ts | 5 +++-- .../store/preprint-stepper/preprint-stepper.selectors.ts | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/app/features/preprints/services/preprints-projects.service.ts b/src/app/features/preprints/services/preprints-projects.service.ts index 4bffbd5bd..1f1eed57b 100644 --- a/src/app/features/preprints/services/preprints-projects.service.ts +++ b/src/app/features/preprints/services/preprints-projects.service.ts @@ -12,6 +12,7 @@ import { NodesResponseJsonApi, } from '@osf/shared/models/nodes/nodes-json-api.model'; import { JsonApiService } from '@osf/shared/services/json-api.service'; +import { replaceBadEncodedChars } from '@shared/helpers/format-bad-encoding.helper'; import { PreprintsMapper } from '../mappers'; import { @@ -44,7 +45,7 @@ export class PreprintsProjectsService { map((response) => { return response.data.map((item) => ({ id: item.id, - name: item.attributes.title, + name: replaceBadEncodedChars(item.attributes.title), })); }) ); @@ -55,7 +56,7 @@ export class PreprintsProjectsService { map((response) => { return { id: response.data.id, - name: response.data.attributes.title, + name: replaceBadEncodedChars(response.data.attributes.title), }; }) ); diff --git a/src/app/features/preprints/store/preprint-stepper/preprint-stepper.selectors.ts b/src/app/features/preprints/store/preprint-stepper/preprint-stepper.selectors.ts index 314b21f12..09b9cb09a 100644 --- a/src/app/features/preprints/store/preprint-stepper/preprint-stepper.selectors.ts +++ b/src/app/features/preprints/store/preprint-stepper/preprint-stepper.selectors.ts @@ -1,6 +1,6 @@ import { Selector } from '@ngxs/store'; -import { PreprintStepperState, PreprintStepperStateModel } from '@osf/features/preprints/store/preprint-stepper' +import { PreprintStepperState, PreprintStepperStateModel } from '@osf/features/preprints/store/preprint-stepper'; export class PreprintStepperSelectors { @Selector([PreprintStepperState])