Skip to content

Commit

Permalink
reduce code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
banders committed Sep 27, 2024
1 parent f703035 commit 678be44
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ import {
import ReportsWidget from './ReportsWidget.vue';
import ApiService from '../../services/apiService';
import { formatIsoDateTimeAsLocalDate } from '../../utils/date';
import { ref, onMounted, onUnmounted } from 'vue';
import {
ReportChangeService,
ReportChangedEventPayload,
} from '../../services/reportChangeService';
import { ref } from 'vue';
const pageSize = 5;
const reportsWidget = ref<typeof ReportsWidget>();
Expand Down Expand Up @@ -60,19 +56,6 @@ const headers = [
},
];
onMounted(() => {
ReportChangeService.listen(onAnyReportChanged);
});
onUnmounted(() => {
ReportChangeService.unlisten(onAnyReportChanged);
});
function onAnyReportChanged(payload: ReportChangedEventPayload) {
console.log(`recentlySubmittedReports - onAnyReportChanged`);
refresh();
}
async function getRecentlySubmittedReports(): Promise<Report[]> {
const filter: ReportFilterType = [];
const sort: IReportSearchSort = [{ update_date: 'desc' }];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ import {
import ReportsWidget from './ReportsWidget.vue';
import ApiService from '../../services/apiService';
import { formatIsoDateTimeAsLocalDate } from '../../utils/date';
import { ref, onMounted, onUnmounted } from 'vue';
import {
ReportChangeService,
ReportChangedEventPayload,
} from '../../services/reportChangeService';
import { ref } from 'vue';
const pageSize = 5;
const reportsWidget = ref<typeof ReportsWidget>();
Expand All @@ -56,19 +52,6 @@ const headers = [
},
];
onMounted(() => {
ReportChangeService.listen(onAnyReportChanged);
});
onUnmounted(() => {
ReportChangeService.unlisten(onAnyReportChanged);
});
function onAnyReportChanged(payload: ReportChangedEventPayload) {
console.log(`recentlyViewedReports - onAnyReportChanged`);
refresh();
}
async function refresh() {
await reportsWidget.value?.refresh();
}
Expand Down
18 changes: 17 additions & 1 deletion admin-frontend/src/components/dashboard/ReportsWidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ export default {
*/
import { Report } from '../../types/reports';
import { ref } from 'vue';
import { ref, onMounted, onUnmounted } from 'vue';
import ReportActions from '../reports/ReportActions.vue';
import {
ReportChangeService,
ReportChangedEventPayload,
} from '../../services/reportChangeService';
const props = defineProps<{
pageSize: string | number | undefined;
Expand All @@ -66,6 +70,18 @@ const isSearching = ref<boolean>(false);
const hasSearched = ref<boolean>(false);
const reports = ref<Report[]>();
onMounted(() => {
ReportChangeService.listen(onAnyReportChanged);
});
onUnmounted(() => {
ReportChangeService.unlisten(onAnyReportChanged);
});
function onAnyReportChanged(payload: ReportChangedEventPayload) {
refresh();
}
/**
* Refresh the reports
*/
Expand Down

0 comments on commit 678be44

Please sign in to comment.