Skip to content

Commit db5e325

Browse files
committed
feat(panel): support release date
1 parent 750ee44 commit db5e325

File tree

4 files changed

+81
-19
lines changed

4 files changed

+81
-19
lines changed

src/components/views/panel/MoviePanel.vue

+17-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,16 @@ const onListUpdate = async (value: ListEntity['id'], remove: boolean) => {
125125
});
126126
};
127127
128-
const onCollectionUpdate = async (value: PanelButtonsOptions, date?: number) => {
128+
const releaseDate = computed(() => movie.value?.released);
129+
130+
const onCollectionUpdate = async (
131+
value: PanelButtonsOptions,
132+
date?: string | number | Date,
133+
) => {
129134
if (!movie.value?.ids) return;
135+
if (date === undefined && value === PanelButtonsOption.Release) {
136+
date = releaseDate.value;
137+
}
130138
131139
await addToOrRemoveFromList({
132140
list: DefaultLists.ShowCollection,
@@ -141,8 +149,14 @@ const onCollectionUpdate = async (value: PanelButtonsOptions, date?: number) =>
141149
changeMovieCollected(_id, value === PanelButtonsOption.Remove);
142150
};
143151
144-
const onWatchedUpdate = async (value: PanelButtonsOptions, date?: number) => {
152+
const onWatchedUpdate = async (
153+
value: PanelButtonsOptions,
154+
date?: string | number | Date,
155+
) => {
145156
if (!movie.value?.ids) return;
157+
if (date === undefined && value === PanelButtonsOption.Release) {
158+
date = releaseDate.value;
159+
}
146160
147161
await addToOrRemoveFromList({
148162
list: {
@@ -204,6 +218,7 @@ const { openTab } = useExtensionSettingsStore();
204218
:collected-loading="collectionLoading"
205219
:active-loading="listLoading"
206220
:active-lists="activeLists"
221+
:has-release="!!releaseDate"
207222
@on-list-update="onListUpdate"
208223
@on-collection-update="onCollectionUpdate"
209224
@on-watched-update="onWatchedUpdate"

src/components/views/panel/MoviePanelButtons.vue

+15-5
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ const props = defineProps({
4747
type: Boolean,
4848
required: false,
4949
},
50+
hasRelease: {
51+
type: Boolean,
52+
required: false,
53+
},
5054
});
5155
5256
const emit = defineEmits<{
@@ -55,7 +59,7 @@ const emit = defineEmits<{
5559
(e: 'onWatchedUpdate', value: PanelButtonsOptions, date?: number): void;
5660
}>();
5761
58-
const { watched, collected, activeLoading, activeLists } = toRefs(props);
62+
const { watched, collected, activeLoading, activeLists, hasRelease } = toRefs(props);
5963
6064
const onListUpdate = (value: ListEntity['id'] | ListEntity['id'][]) => {
6165
const newList = Array.isArray(value) ? value : [value];
@@ -84,13 +88,19 @@ const root = ref<HTMLDivElement>();
8488
const { removeOptions, timeOptions } = usePanelButtons();
8589
8690
const watchedOptions = computed(() => {
87-
if (watched.value) return removeOptions;
88-
return timeOptions;
91+
const _options = watched.value ? removeOptions : timeOptions;
92+
if (!hasRelease.value) {
93+
return _options.filter(option => option.value !== PanelButtonsOption.Release);
94+
}
95+
return _options;
8996
});
9097
9198
const collectionOptions = computed(() => {
92-
if (collected.value) return removeOptions;
93-
return timeOptions;
99+
const _options = collected.value ? removeOptions : timeOptions;
100+
if (!hasRelease.value) {
101+
return _options.filter(option => option.value !== PanelButtonsOption.Release);
102+
}
103+
return _options;
94104
});
95105
96106
const { lists, listsLoading } = useListsStoreRefs();

src/components/views/panel/ShowPanel.vue

+17-2
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ const titleUrl = computed(() => {
227227
});
228228
});
229229
230+
const releaseDate = computed(() => activeItem.value?.first_aired);
231+
230232
const onListUpdate = async (value: ListEntity['id'], remove: boolean) => {
231233
if (!panelType.value || !activeItem.value?.ids) return;
232234
const _list = lists.value.find(list => list.id === value);
@@ -240,8 +242,14 @@ const onListUpdate = async (value: ListEntity['id'], remove: boolean) => {
240242
});
241243
};
242244
243-
const onCollectionUpdate = async (value: PanelButtonsOptions, date?: number) => {
245+
const onCollectionUpdate = async (
246+
value: PanelButtonsOptions,
247+
date?: string | number | Date,
248+
) => {
244249
if (!panelType.value || !activeItem.value?.ids) return;
250+
if (date === undefined && value === PanelButtonsOption.Release) {
251+
date = releaseDate.value;
252+
}
245253
246254
await addToOrRemoveFromList({
247255
list: DefaultLists.ShowCollection,
@@ -254,8 +262,14 @@ const onCollectionUpdate = async (value: PanelButtonsOptions, date?: number) =>
254262
await fetchShowCollectionProgress(showId.value, { force: true });
255263
};
256264
257-
const onWatchedUpdate = async (value: PanelButtonsOptions, date?: number) => {
265+
const onWatchedUpdate = async (
266+
value: PanelButtonsOptions,
267+
date?: string | number | Date,
268+
) => {
258269
if (!panelType.value || !activeItem.value?.ids) return;
270+
if (date === undefined && value === PanelButtonsOption.Release) {
271+
date = releaseDate.value;
272+
}
259273
260274
await addToOrRemoveFromList({
261275
list: {
@@ -332,6 +346,7 @@ const { openTab } = useExtensionSettingsStore();
332346
:collection-loading="collectionLoading"
333347
:active-loading="listLoading"
334348
:active-lists="activeLists"
349+
:has-release="!!releaseDate"
335350
@on-list-update="onListUpdate"
336351
@on-collection-update="onCollectionUpdate"
337352
@on-watched-update="onWatchedUpdate"

src/components/views/panel/ShowPanelButtons.vue

+32-10
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ const props = defineProps({
5858
type: Boolean,
5959
required: false,
6060
},
61+
hasRelease: {
62+
type: Boolean,
63+
required: false,
64+
},
6165
});
6266
6367
const emit = defineEmits<{
@@ -66,8 +70,14 @@ const emit = defineEmits<{
6670
(e: 'onWatchedUpdate', value: PanelButtonsOptions, date?: number): void;
6771
}>();
6872
69-
const { mode, watchedProgress, collectionProgress, activeLoading, activeLists } =
70-
toRefs(props);
73+
const {
74+
mode,
75+
watchedProgress,
76+
collectionProgress,
77+
activeLoading,
78+
activeLists,
79+
hasRelease,
80+
} = toRefs(props);
7181
7282
const onListUpdate = (value: ListEntity['id'] | ListEntity['id'][]) => {
7383
const newList = Array.isArray(value) ? value : [value];
@@ -122,19 +132,31 @@ const root = ref<HTMLDivElement>();
122132
const { removeOptions, mixedOptions, timeOptions } = usePanelButtons();
123133
124134
const watchedOptions = computed(() => {
125-
if (watched.value) return removeOptions;
126-
if (watchedPercentage.value > 0 && watchedPercentage.value < 100) {
127-
return mixedOptions;
135+
const _options = [];
136+
if (watched.value) _options.push(...removeOptions);
137+
else if (watchedPercentage.value > 0 && watchedPercentage.value < 100) {
138+
_options.push(...mixedOptions);
139+
} else {
140+
_options.push(...timeOptions);
128141
}
129-
return timeOptions;
142+
if (!hasRelease.value) {
143+
return _options.filter(option => option.value !== PanelButtonsOption.Release);
144+
}
145+
return _options;
130146
});
131147
132148
const collectionOptions = computed(() => {
133-
if (collected.value) return removeOptions;
134-
if (collectionPercentage.value > 0 && collectionPercentage.value < 100) {
135-
return mixedOptions;
149+
const _options = [];
150+
if (collected.value) _options.push(...removeOptions);
151+
else if (collectionPercentage.value > 0 && collectionPercentage.value < 100) {
152+
_options.push(...mixedOptions);
153+
} else {
154+
_options.push(...timeOptions);
155+
}
156+
if (!hasRelease.value) {
157+
return _options.filter(option => option.value !== PanelButtonsOption.Release);
136158
}
137-
return timeOptions;
159+
return _options;
138160
});
139161
140162
const { lists, listsLoading } = useListsStoreRefs();

0 commit comments

Comments
 (0)