Skip to content

Commit

Permalink
(Fix: #91) Refactor _season.vue to remove unnecessary whitespace an…
Browse files Browse the repository at this point in the history
…d improve code readability
  • Loading branch information
tachibana-shin committed Aug 2, 2024
1 parent dd271a5 commit 457b042
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions src/pages/phim/_season.vue
Original file line number Diff line number Diff line change
Expand Up @@ -731,20 +731,17 @@ const { data, run, error, loading } = useRequest(
if (!id) return Promise.reject()
let result: Ref<Awaited<ReturnType<typeof PhimId>>>
await Promise.any([
get(`data-${id}`).then((text: string) => {
if (!text) throw new Error("not_found")
console.log("[fs]: use cache from fs %s", id)
// eslint-disable-next-line promise/always-return
if (!result) result = ref(JSON.parse(text))
}),
PhimId(realIdCurrentSeason.value)
.then(async (data) => {
let changed = !result // true if result is undefined
const watcher =
result &&
Expand Down Expand Up @@ -917,10 +914,11 @@ async function fetchSeason(season: string) {
console.log("data from internet is ", data)
}
responseOnlineStore.add(response)
Object.assign(response.value, { [__ONLINE__]: true })
}),
(promiseLoadIndexedb = get(`season_data ${realIdSeason}`).then(
(json?: string) => {
if (!json) throw new Error("not_found")
console.log("[fs]: use cache %s", realIdSeason)
if (!response.value) response.value = JSON.parse(json)
Expand Down Expand Up @@ -951,7 +949,6 @@ async function fetchSeason(season: string) {
function watchHandler() {
if (!seasons.value || !response.value) return
let indexMetaSeason = seasons.value.findIndex(
(item) => item.value === season
)
Expand Down Expand Up @@ -1009,7 +1006,6 @@ async function fetchSeason(season: string) {
return responseOnlineStore.has(response)
}
let watcherResponse: (() => void) | undefined = watch(response, () => {
const doneAll = watchHandler()
if (doneAll) {
Expand Down Expand Up @@ -1095,7 +1091,6 @@ const currentProgresWatch = computed(() => {
return undefined
})
let watcherChangeIdFirstEp: (() => void) | null = null
onBeforeUnmount(() => watcherChangeIdFirstEp?.())
/** @type - currentChap is episode id */
Expand Down Expand Up @@ -1142,7 +1137,6 @@ watchEffect(async (onCleanup): Promise<void> => {
if (episodeId !== undefined) {
if (episodeId) {
let watcher: () => void
// eslint-disable-next-line prefer-const
watcher = watchEffect(() => {
Expand Down Expand Up @@ -1238,7 +1232,7 @@ watchEffect(() => {
})
} else {
if (import.meta.env.DEV) console.warn("Redirect to not_found")
if (data.value && __ONLINE__ in data.value)
if (data.value && __ONLINE__ in data.value && __ONLINE__ in currentDataSeason.value)
router.replace({
name: "not_found",
params: {
Expand Down Expand Up @@ -1437,7 +1431,6 @@ watch(
configPlayer.value = undefined
let typeCurrentConfig: keyof typeof servers | null = null
let loadedServerFB = false
Expand Down Expand Up @@ -1698,7 +1691,7 @@ async function addAnimePlaylist(idPlaylist: number) {
name_season: metaSeason.name,
chap: currentChap.value,
name_chap: currentMetaChap.value.name,
season: currentSeason.value
season: currentSeason.value,
})
$q.notify({
position: "bottom-right",
Expand Down Expand Up @@ -1761,7 +1754,6 @@ const episodesOpEnd = computedAsync<ShallowReactive<ListEpisodes> | null>(
const controller = new AbortController()
onCleanup(() => controller.abort())
let results: ShallowReactive<ListEpisodes>
await Promise.any([
fetch(
Expand Down Expand Up @@ -1789,7 +1781,6 @@ const episodesOpEnd = computedAsync<ShallowReactive<ListEpisodes> | null>(
} else results = shallowReactive(data)
}),
get(`episodes_opend:${realId}`).then((text: string) => {
if (!text) throw new Error("not_found_on_idb")
const data = JSON.parse(text)
Expand Down Expand Up @@ -1864,7 +1855,6 @@ const inoutroEpisode = computedAsync<ShallowReactive<InOutroEpisode> | null>(
const { id } = episodeOpEnd.value
let results: ShallowReactive<InOutroEpisode>
await Promise.any([
fetch(`${API_OPEND}/episode-skip/${id}`)
Expand All @@ -1879,7 +1869,6 @@ const inoutroEpisode = computedAsync<ShallowReactive<InOutroEpisode> | null>(
} else results = shallowReactive(data)
}),
get(`inoutro:${id}`).then((text: string) => {
if (!text) throw new Error("not_found_on_idb")
const data = JSON.parse(text)
Expand Down

0 comments on commit 457b042

Please sign in to comment.