Skip to content

Commit

Permalink
🎨 Clean up codebase (#2962)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaVandaele authored Aug 27, 2024
1 parent 7e1adde commit 69ef1c3
Show file tree
Hide file tree
Showing 56 changed files with 955 additions and 1,120 deletions.
31 changes: 17 additions & 14 deletions client/app/components/MainSearchBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,23 @@ const onAutocompleteSelectedValueUpdate = (value: number) => {
};
const onSearchFieldKeydown = (e: any) => {
if (e.key === 'ArrowDown') {
if (autocompleteSelectedValue.value + 2 <= autocompleteValues.value.length) {
autocompleteSelectedValue.value += 1;
} else {
autocompleteSelectedValue.value = 0;
}
localSearchValue.value = autocompleteValues.value[autocompleteSelectedValue.value];
} else if (e.key === 'ArrowUp') {
if (autocompleteSelectedValue.value - 1 >= 0) {
autocompleteSelectedValue.value -= 1;
} else {
autocompleteSelectedValue.value = autocompleteValues.value.length - 1;
}
localSearchValue.value = autocompleteValues.value[autocompleteSelectedValue.value];
switch (e.key) {
case 'ArrowDown':
if (autocompleteSelectedValue.value + 2 <= autocompleteValues.value.length) {
autocompleteSelectedValue.value += 1;
} else {
autocompleteSelectedValue.value = 0;
}
localSearchValue.value = autocompleteValues.value[autocompleteSelectedValue.value];
break;
case 'ArrowUp':
if (autocompleteSelectedValue.value - 1 >= 0) {
autocompleteSelectedValue.value -= 1;
} else {
autocompleteSelectedValue.value = autocompleteValues.value.length - 1;
}
localSearchValue.value = autocompleteValues.value[autocompleteSelectedValue.value];
break;
}
e.stopPropagation();
return true;
Expand Down
8 changes: 3 additions & 5 deletions client/app/components/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,13 @@ const videoSpeedArray = [
];
function setSponsorBlockUrl() {
if (!isSponsorBlockUrlValid.value) {
return;
if (isSponsorBlockUrlValid.value) {
settingsStore.sponsorblockUrl = sponsorBlockUrl.value;
}
settingsStore.sponsorblockUrl = sponsorBlockUrl.value;
}
function resetSponsorBlockUrl() {
settingsStore.sponsorblockUrl = 'https://sponsor.ajay.app/';
sponsorBlockUrl.value = settingsStore.sponsorblockUrl;
settingsStore.sponsorblockUrl = sponsorBlockUrl.value = 'https://sponsor.ajay.app/';
}
</script>

Expand Down
4 changes: 1 addition & 3 deletions client/app/components/VTIcon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ const props = withDefaults(
);
const iconName = computed((): string => {
if (!props.name) {
return '';
}
if (!props.name) return '';
return `i-${props.name.replace(':', '-')}`;
});
</script>
Expand Down
51 changes: 25 additions & 26 deletions client/app/components/admin/CreateUser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,34 @@ const { createUser } = useCreateUser();
const messagesStore = useMessagesStore();
const createUserAdmin = async () => {
if (username.value && password.value) {
const createdUser = await createUser({
username: username.value,
password: password.value
})
.then(
res => res,
reason => {
throw reason;
}
)
.catch(err => {
messagesStore.createMessage({
type: 'error',
title: 'Error creating user',
message: err?.data?.message ?? 'Unknown error'
});
if (!username.value || !password.value) return;
const createdUser = await createUser({
username: username.value,
password: password.value
})
.then(
res => res,
reason => {
throw reason;
}
)
.catch(err => {
messagesStore.createMessage({
type: 'error',
title: 'Error creating user',
message: err?.data?.message ?? 'Unknown error'
});
});
username.value = '';
password.value = '';
username.value = '';
password.value = '';
if (createdUser) {
messagesStore.createMessage({
type: 'info',
title: 'User created',
message: `User ${createdUser.username} created`
});
}
if (createdUser) {
messagesStore.createMessage({
type: 'info',
title: 'User created',
message: `User ${createdUser.username} created`
});
}
};
</script>
Expand Down
141 changes: 67 additions & 74 deletions client/app/components/buttons/SubscribeButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,89 +62,82 @@ export default defineComponent({
});
const loadSubscriptionStatus = (): void => {
if (props.channelId && userStore.isLoggedIn) {
vtFetch<ApiDto<'SubscriptionStatusDto'>>(
`${apiUrl.value}user/subscriptions/${props.channelId}`,
{
credentials: 'include'
}
)
.then(response => {
if (response.isSubscribed) {
isSubscribed.value = true;
} else {
isSubscribed.value = false;
}
disabled.value = false;
})
.catch((_: any) => {
isSubscribed.value = false;
disabled.value = true;
});
}
if (!props.channelId || !userStore.isLoggedIn) return;
vtFetch<ApiDto<'SubscriptionStatusDto'>>(
`${apiUrl.value}user/subscriptions/${props.channelId}`,
{
credentials: 'include'
}
)
.then(response => {
isSubscribed.value = response.isSubscribed;
disabled.value = false;
})
.catch((_: any) => {
isSubscribed.value = false;
disabled.value = true;
});
};
const subscribe = (): void => {
if (props.channelId) {
disabled.value = true;
vtFetch<ApiDto<'SubscriptionStatusDto'>>(
`${apiUrl.value}user/subscriptions/${props.channelId}`,
{
method: 'PUT',
credentials: 'include'
}
)
.then(response => {
if (response.isSubscribed) {
isSubscribed.value = true;
messagesStore.createMessage({
type: 'info',
title: 'Subscribed',
message: `Successfully subscribed. Fetching new videos can take some time.`
});
}
disabled.value = false;
if (props.small) {
expanded.value = false;
}
})
.catch((_: any) => {
if (!props.channelId) return;
disabled.value = true;
vtFetch<ApiDto<'SubscriptionStatusDto'>>(
`${apiUrl.value}user/subscriptions/${props.channelId}`,
{
method: 'PUT',
credentials: 'include'
}
)
.then(response => {
if (response.isSubscribed) {
isSubscribed.value = true;
messagesStore.createMessage({
type: 'error',
title: 'Unable to subscribe',
message: `You may not be logged in. Try reloading the page.`
type: 'info',
title: 'Subscribed',
message: `Successfully subscribed. Fetching new videos can take some time.`
});
disabled.value = false;
}
disabled.value = false;
if (props.small) {
expanded.value = false;
}
})
.catch((_: any) => {
messagesStore.createMessage({
type: 'error',
title: 'Unable to subscribe',
message: `You may not be logged in. Try reloading the page.`
});
}
disabled.value = false;
});
};
const unsubscribe = (): void => {
if (props.channelId) {
disabled.value = true;
vtFetch<ApiDto<'SubscriptionStatusDto'>>(
`${apiUrl.value}user/subscriptions/${props.channelId}`,
{
method: 'DELETE',
credentials: 'include'
if (!props.channelId) return;
disabled.value = true;
vtFetch<ApiDto<'SubscriptionStatusDto'>>(
`${apiUrl.value}user/subscriptions/${props.channelId}`,
{
method: 'DELETE',
credentials: 'include'
}
)
.then(response => {
if (!response.isSubscribed) {
isSubscribed.value = false;
}
)
.then(response => {
if (!response.isSubscribed) {
isSubscribed.value = false;
}
disabled.value = false;
if (props.small) {
expanded.value = false;
}
})
.catch((_: any) => {
messagesStore.createMessage({
type: 'error',
title: 'Unable to unsubscribe',
message: `You may not be logged in. Try to reload the page.`
});
disabled.value = false;
disabled.value = false;
if (props.small) {
expanded.value = false;
}
})
.catch((_: any) => {
messagesStore.createMessage({
type: 'error',
title: 'Unable to unsubscribe',
message: `You may not be logged in. Try to reload the page.`
});
}
disabled.value = false;
});
};
return {
Expand Down
37 changes: 18 additions & 19 deletions client/app/components/channel/page/Channels.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,25 @@ const channelInfo = ref(data);
const morePending = ref(false);
const loadMore = async () => {
if (!channelInfo.value.relatedChannels.continuation) return;
morePending.value = true;
if (channelInfo.value.relatedChannels.continuation) {
try {
const additionalChannels = await getRelatedChannelsContinuation(
channelInfo.value.relatedChannels.continuation
);
channelInfo.value.relatedChannels.items = [
...(channelInfo.value.relatedChannels.items as any),
...additionalChannels.items
];
channelInfo.value.relatedChannels.continuation = additionalChannels.continuation;
} catch (error) {
messagesStore.createMessage({
type: 'error',
title: 'Failed to load more channels',
message:
(error as any).message ??
"More channels don't seem to be available, or something went wrong."
});
}
try {
const additionalChannels = await getRelatedChannelsContinuation(
channelInfo.value.relatedChannels.continuation
);
channelInfo.value.relatedChannels.items = [
...(channelInfo.value.relatedChannels.items as any),
...additionalChannels.items
];
channelInfo.value.relatedChannels.continuation = additionalChannels.continuation;
} catch (error) {
messagesStore.createMessage({
type: 'error',
title: 'Failed to load more channels',
message:
(error as any).message ??
"More channels don't seem to be available, or something went wrong."
});
}
morePending.value = false;
};
Expand Down
41 changes: 20 additions & 21 deletions client/app/components/channel/page/Community.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,27 @@ const morePending = ref(false);
const communityPosts = ref(data);
const loadMore = async () => {
if (!communityPosts.value?.continuation) return;
morePending.value = true;
if (communityPosts.value?.continuation) {
try {
const additionalCommunityPosts = await getChannelCommunityPostsContinuation(
communityPosts.value?.continuation,
communityPosts.value?.innerTubeApi
);
communityPosts.value.items = [
...communityPosts.value.items,
...additionalCommunityPosts.items
];
communityPosts.value.continuation = additionalCommunityPosts.continuation;
communityPosts.value.innerTubeApi = additionalCommunityPosts.innerTubeApi;
} catch (error) {
messagesStore.createMessage({
type: 'error',
title: 'Failed to load more community posts',
message:
(error as any).message ??
"More community posts don't seem to be available, or something went wrong."
});
}
try {
const additionalCommunityPosts = await getChannelCommunityPostsContinuation(
communityPosts.value?.continuation,
communityPosts.value?.innerTubeApi
);
communityPosts.value.items = [
...communityPosts.value.items,
...additionalCommunityPosts.items
];
communityPosts.value.continuation = additionalCommunityPosts.continuation;
communityPosts.value.innerTubeApi = additionalCommunityPosts.innerTubeApi;
} catch (error) {
messagesStore.createMessage({
type: 'error',
title: 'Failed to load more community posts',
message:
(error as any).message ??
"More community posts don't seem to be available, or something went wrong."
});
}
morePending.value = false;
};
Expand Down
7 changes: 3 additions & 4 deletions client/app/components/filter/Dropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ type entriesArray = Array<{ name: string; value: string }>;
const entries = computed((): entriesArray => {
if (props.values[0].value && props.values[0].name) {
return props.values;
} else {
return props.values.map(value => {
return { name: value, value };
});
}
return props.values.map(value => {
return { name: value, value };
});
});
const calculateOffset = (): void => {
Expand Down
Loading

0 comments on commit 69ef1c3

Please sign in to comment.