Skip to content

Commit 7bfaf95

Browse files
pkp/pkp-lib#6278 Add reload capability to submission wizard
1 parent 0fea7cd commit 7bfaf95

File tree

2 files changed

+55
-19
lines changed

2 files changed

+55
-19
lines changed

src/components/Container/SubmissionWizardPage.vue

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ import autosave from '@/mixins/autosave';
1313
import dialog from '@/mixins/dialog';
1414
import localizeSubmission from '@/mixins/localizeSubmission';
1515
import localStorage from '@/mixins/localStorage';
16+
import {getCurrentInstance} from 'vue';
1617
import {useDate} from '@/composables/useDate';
18+
import {useDataChangedProvider} from '@/composables/useDataChangedProvider';
19+
import {useFetch} from '@/composables/useFetch';
1720
import {useModal} from '@/composables/useModal';
1821
1922
export default {
@@ -24,10 +27,24 @@ export default {
2427
File,
2528
Modal,
2629
SubmissionFilesListPanel,
27-
DataCitationManager
30+
DataCitationManager,
2831
},
2932
extends: Page,
3033
mixins: [ajaxError, autosave, dialog, localizeSubmission, localStorage],
34+
setup() {
35+
const instance = getCurrentInstance();
36+
37+
const {triggerDataChange} = useDataChangedProvider(async () => {
38+
await Promise.all([
39+
instance.proxy.reloadSubmission(),
40+
instance.proxy.reloadPublication(),
41+
]);
42+
});
43+
44+
return {
45+
triggerDataChange,
46+
};
47+
},
3148
data() {
3249
return {
3350
/** A unique string. See autosave mixin below. */
@@ -611,6 +628,28 @@ export default {
611628
this.publication = newPublication;
612629
},
613630
631+
/**
632+
* Reload the submission from the API
633+
*/
634+
async reloadSubmission() {
635+
const {data, fetch} = useFetch(this.submissionApiUrl);
636+
await fetch();
637+
if (data.value) {
638+
this.submission = data.value;
639+
}
640+
},
641+
642+
/**
643+
* Reload the publication from the API
644+
*/
645+
async reloadPublication() {
646+
const {data, fetch} = useFetch(this.publicationApiUrl);
647+
await fetch();
648+
if (data.value) {
649+
this.publication = data.value;
650+
}
651+
},
652+
614653
/**
615654
* Complete the submission
616655
*

src/managers/DataCitationManager/dataCitationManagerStore.js

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import {computed, onUnmounted, ref, toRefs} from 'vue';
2-
import {useUrl} from '@/composables/useUrl';
3-
import {useFetch} from '@/composables/useFetch';
1+
import {computed, toRefs} from 'vue';
42
import {defineComponentStore} from '@/utils/defineComponentStore';
53
import {useExtender} from '@/composables/useExtender';
4+
import {useDataChanged} from '@/composables/useDataChanged';
65
import {useDataCitationManagerConfig} from './useDataCitationManagerConfig';
76
import {useDataCitationManagerActions} from './useDataCitationManagerActions';
87

98
export const useDataCitationManagerStore = defineComponentStore(
109
'dataCitationManager',
1110
(props) => {
12-
1311
const extender = useExtender();
14-
const dataCitationManagerConfig = extender.addFns(useDataCitationManagerConfig());
12+
const dataCitationManagerConfig = extender.addFns(
13+
useDataCitationManagerConfig(),
14+
);
1515
const columns = computed(() => dataCitationManagerConfig.getColumns());
1616
const topItems = computed(() => dataCitationManagerConfig.getTopItems());
1717

@@ -22,26 +22,23 @@ export const useDataCitationManagerStore = defineComponentStore(
2222
});
2323
}
2424

25-
const {
26-
submission,
27-
publication,
28-
} = toRefs(props);
29-
30-
const { apiUrl } = useUrl(`dataCitations/publications/${publication.value.id}`);
31-
const {data: apiResponse, fetch: fetchDataCitations} = useFetch(apiUrl, {
32-
method: 'GET',
33-
});
25+
const {submission, publication} = toRefs(props);
26+
27+
// Get data citations directly from publication prop
28+
const dataCitations = computed(
29+
() => publication.value?.dataCitations ?? [],
30+
);
3431

35-
fetchDataCitations();
36-
const dataCitations = computed(() => { return apiResponse.value?.items ?? []; });
32+
// Use triggerDataChange to notify parent to refetch submission/publication
33+
const {triggerDataChange} = useDataChanged();
3734

3835
/**
3936
* Actions
4037
*/
4138
const dataCitationManagerActions = useDataCitationManagerActions();
4239

4340
function dataUpdateCallback() {
44-
fetchDataCitations();
41+
triggerDataChange();
4542
}
4643

4744
function getActionArgs(additionalArgs = {}) {
@@ -52,7 +49,7 @@ export const useDataCitationManagerStore = defineComponentStore(
5249
...additionalArgs,
5350
};
5451
}
55-
function dataCitationAddDataCitation({}) {
52+
function dataCitationAddDataCitation() {
5653
dataCitationManagerActions.dataCitationAddDataCitation(
5754
getActionArgs({}),
5855
dataUpdateCallback,

0 commit comments

Comments
 (0)