|
| 1 | +import { createDispatchMap, select } from '@ngxs/store'; |
| 2 | + |
| 3 | +import { TranslatePipe } from '@ngx-translate/core'; |
| 4 | + |
| 5 | +import { Accordion, AccordionContent, AccordionHeader, AccordionPanel } from 'primeng/accordion'; |
| 6 | +import { Card } from 'primeng/card'; |
| 7 | +import { Skeleton } from 'primeng/skeleton'; |
| 8 | +import { Tag } from 'primeng/tag'; |
| 9 | + |
| 10 | +import { DatePipe } from '@angular/common'; |
| 11 | +import { ChangeDetectionStrategy, Component, computed, effect, input, OnDestroy } from '@angular/core'; |
| 12 | + |
| 13 | +import { PreprintDoiSectionComponent } from '@osf/features/preprints/components/preprint-details/preprint-doi-section/preprint-doi-section.component'; |
| 14 | +import { ApplicabilityStatus, PreregLinkInfo } from '@osf/features/preprints/enums'; |
| 15 | +import { PreprintProviderDetails } from '@osf/features/preprints/models'; |
| 16 | +import { FetchPreprintById, PreprintSelectors } from '@osf/features/preprints/store/preprint'; |
| 17 | +import { TruncatedTextComponent } from '@shared/components'; |
| 18 | +import { ResourceType } from '@shared/enums'; |
| 19 | +import { InterpolatePipe } from '@shared/pipes'; |
| 20 | +import { |
| 21 | + ContributorsSelectors, |
| 22 | + FetchSelectedSubjects, |
| 23 | + GetAllContributors, |
| 24 | + ResetContributorsState, |
| 25 | + SubjectsSelectors, |
| 26 | +} from '@shared/stores'; |
| 27 | + |
| 28 | +@Component({ |
| 29 | + selector: 'osf-preprint-tombstone', |
| 30 | + imports: [ |
| 31 | + Card, |
| 32 | + PreprintDoiSectionComponent, |
| 33 | + Skeleton, |
| 34 | + TranslatePipe, |
| 35 | + TruncatedTextComponent, |
| 36 | + Accordion, |
| 37 | + AccordionContent, |
| 38 | + Tag, |
| 39 | + AccordionPanel, |
| 40 | + AccordionHeader, |
| 41 | + InterpolatePipe, |
| 42 | + DatePipe, |
| 43 | + ], |
| 44 | + templateUrl: './preprint-tombstone.component.html', |
| 45 | + styleUrl: './preprint-tombstone.component.scss', |
| 46 | + changeDetection: ChangeDetectionStrategy.OnPush, |
| 47 | +}) |
| 48 | +export class PreprintTombstoneComponent implements OnDestroy { |
| 49 | + readonly ApplicabilityStatus = ApplicabilityStatus; |
| 50 | + readonly PreregLinkInfo = PreregLinkInfo; |
| 51 | + |
| 52 | + private actions = createDispatchMap({ |
| 53 | + getContributors: GetAllContributors, |
| 54 | + resetContributorsState: ResetContributorsState, |
| 55 | + fetchPreprintById: FetchPreprintById, |
| 56 | + fetchSubjects: FetchSelectedSubjects, |
| 57 | + }); |
| 58 | + preprintProvider = input.required<PreprintProviderDetails | undefined>(); |
| 59 | + |
| 60 | + preprint = select(PreprintSelectors.getPreprint); |
| 61 | + isPreprintLoading = select(PreprintSelectors.isPreprintLoading); |
| 62 | + |
| 63 | + contributors = select(ContributorsSelectors.getContributors); |
| 64 | + areContributorsLoading = select(ContributorsSelectors.isContributorsLoading); |
| 65 | + bibliographicContributors = computed(() => { |
| 66 | + return this.contributors().filter((contributor) => contributor.isBibliographic); |
| 67 | + }); |
| 68 | + subjects = select(SubjectsSelectors.getSelectedSubjects); |
| 69 | + areSelectedSubjectsLoading = select(SubjectsSelectors.areSelectedSubjectsLoading); |
| 70 | + |
| 71 | + license = computed(() => { |
| 72 | + const preprint = this.preprint(); |
| 73 | + if (!preprint) return null; |
| 74 | + return preprint.embeddedLicense; |
| 75 | + }); |
| 76 | + licenseOptionsRecord = computed(() => { |
| 77 | + return (this.preprint()?.licenseOptions ?? {}) as Record<string, string>; |
| 78 | + }); |
| 79 | + |
| 80 | + skeletonData = Array.from({ length: 6 }, () => null); |
| 81 | + |
| 82 | + constructor() { |
| 83 | + effect(() => { |
| 84 | + const preprint = this.preprint(); |
| 85 | + if (!preprint) return; |
| 86 | + |
| 87 | + this.actions.getContributors(this.preprint()!.id, ResourceType.Preprint); |
| 88 | + this.actions.fetchSubjects(this.preprint()!.id, ResourceType.Preprint); |
| 89 | + }); |
| 90 | + } |
| 91 | + |
| 92 | + ngOnDestroy(): void { |
| 93 | + this.actions.resetContributorsState(); |
| 94 | + } |
| 95 | +} |
0 commit comments