Skip to content

Commit a7ec4e2

Browse files
committed
feat(panel): refresh list view on panel close
1 parent db5e325 commit a7ec4e2

File tree

6 files changed

+54
-5
lines changed

6 files changed

+54
-5
lines changed

src/components/AppComponent.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const onBack = () => {
6363
<GridBackground v-if="!Component" :size="20" />
6464
<Transition name="scale" mode="out-in">
6565
<KeepAlive>
66-
<component :is="Component ?? PageLoading" />
66+
<component :is="Component ?? PageLoading" :panel="panel" />
6767
</KeepAlive>
6868
</Transition>
6969
</main>

src/components/views/history/HistoryComponent.vue

+17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<script lang="ts" setup>
2+
import { onMounted, toRefs, watch } from 'vue';
3+
24
import FloatingButton from '~/components/common/buttons/FloatingButton.vue';
35
import { useBackToTop } from '~/components/common/buttons/use-back-to-top';
46
import ListScroll from '~/components/common/list/ListScroll.vue';
@@ -12,6 +14,15 @@ import { useHistoryStore, useHistoryStoreRefs } from '~/stores/data/history.stor
1214
import { useI18n } from '~/utils';
1315
import { watchUserChange } from '~/utils/store.utils';
1416
17+
const props = defineProps({
18+
panel: {
19+
type: Boolean,
20+
required: false,
21+
},
22+
});
23+
24+
const { panel } = toRefs(props);
25+
1526
const { filteredHistory, pagination, loading, pageSize, belowThreshold, searchHistory } =
1627
useHistoryStoreRefs();
1728
const { fetchHistory, clearState } = useHistoryStore();
@@ -23,6 +34,12 @@ watchUserChange({
2334
clear: clearState,
2435
});
2536
37+
onMounted(() => {
38+
watch(panel, async value => {
39+
if (!value) await fetchHistory();
40+
});
41+
});
42+
2643
const list = useListScroll(filteredHistory, 'watched_at');
2744
2845
const history = addLoadMore(list, pagination, searchHistory);

src/components/views/progress/ProgressComponent.vue

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="ts" setup>
22
import { NFlex } from 'naive-ui';
3-
import { onMounted, Transition } from 'vue';
3+
import { onActivated, onMounted, toRefs, Transition, watch } from 'vue';
44
55
import FloatingButton from '~/components/common/buttons/FloatingButton.vue';
66
import { useBackToTop } from '~/components/common/buttons/use-back-to-top';
@@ -12,15 +12,30 @@ import { ExternaLinks } from '~/settings/external.links';
1212
import { useProgressStore, useProgressStoreRefs } from '~/stores/data/progress.store';
1313
import { useI18n } from '~/utils';
1414
15+
const props = defineProps({
16+
panel: {
17+
type: Boolean,
18+
required: false,
19+
},
20+
});
21+
22+
const { panel } = toRefs(props);
23+
1524
const i18n = useI18n('progress');
1625
1726
const { progress, loading, loggedOut } = useProgressStoreRefs();
1827
const { fetchProgress } = useProgressStore();
1928
20-
onMounted(async () => {
29+
onActivated(async () => {
2130
await fetchProgress();
2231
});
2332
33+
onMounted(() => {
34+
watch(panel, async value => {
35+
if (!value) await fetchProgress();
36+
});
37+
});
38+
2439
const { scrolled, listRef, onClick } = useBackToTop();
2540
const { onItemClick } = usePanelItem();
2641
</script>

src/components/views/watchlist/WatchlistComponent.vue

+17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<script lang="ts" setup>
2+
import { onMounted, toRefs, watch } from 'vue';
3+
24
import FloatingButton from '~/components/common/buttons/FloatingButton.vue';
35
import { useBackToTop } from '~/components/common/buttons/use-back-to-top';
46
import ListScroll from '~/components/common/list/ListScroll.vue';
@@ -19,6 +21,15 @@ import {
1921
import { useI18n } from '~/utils';
2022
import { watchUserChange } from '~/utils/store.utils';
2123
24+
const props = defineProps({
25+
panel: {
26+
type: Boolean,
27+
required: false,
28+
},
29+
});
30+
31+
const { panel } = toRefs(props);
32+
2233
const i18n = useI18n('list');
2334
2435
const {
@@ -36,6 +47,12 @@ watchUserChange({
3647
clear: clearState,
3748
});
3849
50+
onMounted(() => {
51+
watch(panel, async value => {
52+
if (!value) await fetchListItems();
53+
});
54+
});
55+
3956
const list = useListScroll<AnyList, AnyListDateTypes>(
4057
filteredListItems,
4158
anyListDateGetter,

src/models/trakt/trakt-history.model.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export type TraktHistoryAdded = {
5151

5252
export type TraktHistoryRemovedRequest = TraktSyncRequest & {
5353
/** Array of history ids. */
54-
ids: number[];
54+
ids?: number[];
5555
};
5656

5757
export type TraktHistoryRemoved = {

src/stores/data/list.store.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ export const useListStore = defineStore('data.list', () => {
334334
return;
335335
}
336336

337-
console.info('Adding item to list', listId, itemType, itemIds);
337+
console.info(`${remove ? 'Removing' : 'Adding'} item to list`, listId, itemType, itemIds);
338338

339339
if (!typeItemLoading[listType]) typeItemLoading[listType] = {};
340340
if (!typeItemLoading[listType]![itemType]) typeItemLoading[listType]![itemType] = {};

0 commit comments

Comments
 (0)