Fix getting locked category

This commit is contained in:
Ajay Ramachandran 2021-10-13 23:57:59 -04:00
parent 27f5997e5a
commit fc7fc693ed
2 changed files with 10 additions and 6 deletions

View file

@ -254,7 +254,7 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
elements.push(
<option value={category}
key={category}
className={this.categoryLockedClass(category)}>
className={this.getCategoryLockedClass(category)}>
{chrome.i18n.getMessage("category_" + category)}
</option>
);

View file

@ -37,7 +37,7 @@ let videoInfo: VideoInfo = null;
// The channel this video is about
let channelIDInfo: ChannelIDInfo;
// Locked Categories in this tab, like: ["sponsor","intro","outro"]
const lockedCategories: Category[] = [];
let lockedCategories: Category[] = [];
// Skips are scheduled to ensure precision.
// Skips are rescheduled every seeking event.
@ -234,6 +234,7 @@ function resetValues() {
status: ChannelIDStatus.Fetching,
id: null
};
lockedCategories = [];
//empty the preview bar
if (previewBar !== null) {
@ -808,10 +809,13 @@ async function lockedSegmentsLookup(): Promise<void> {
async function lockedCategoriesLookup(id: string): Promise<void> {
const response = await utils.asyncRequestToServer("GET", "/api/lockCategories", { videoID: id });
if (response.status === 200 && response.ok) {
for (const category of JSON.parse(response.responseText).categories) {
lockedCategories.push(category);
}
if (response.ok) {
try {
const categoriesResponse = JSON.parse(response.responseText).categories;
if (Array.isArray(categoriesResponse)) {
lockedCategories = categoriesResponse;
}
} catch (e) { } //eslint-disable-line no-empty
}
}