Skip to content

Commit

Permalink
fix: the subtitle belong to error episodes when upload
Browse files Browse the repository at this point in the history
  • Loading branch information
ltaoo committed Sep 8, 2023
1 parent 004499e commit 85a4305
Show file tree
Hide file tree
Showing 18 changed files with 260 additions and 94 deletions.
4 changes: 4 additions & 0 deletions .husky/pre-push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm run check
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@types/qs": "^6.9.7",
"@types/url-parse": "^1.4.8",
"autoprefixer": "^10.4.14",
"husky": "^8.0.3",
"postcss": "^8.4.21",
"tailwindcss": "^3.3.1",
"typescript": "^4.9.5",
Expand Down
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions src/components/TVSeasonSelect/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ enum Events {
ResponseChange,
Change,
Select,
Clear,
}
type TheTypesOfEvents = {
// [Events.Change]: TVSeasonItem;
[Events.Select]: TVSeasonItem;
[Events.Clear]: void;
};
type TVSeasonSelectProps = {
onSelect?: (v: TVSeasonItem) => void;
Expand Down Expand Up @@ -70,6 +72,9 @@ export class TVSeasonSelectCore extends BaseDomain<TheTypesOfEvents> {
});
this.curSeason.onStateChange((nextState) => {
this.value = nextState;
if (nextState === null) {
this.emit(Events.Clear);
}
});
if (onSelect) {
this.onSelect(onSelect);
Expand Down Expand Up @@ -100,6 +105,9 @@ export class TVSeasonSelectCore extends BaseDomain<TheTypesOfEvents> {
onSelect(handler: Handler<TheTypesOfEvents[Events.Select]>) {
return this.on(Events.Select, handler);
}
onClear(handler: Handler<TheTypesOfEvents[Events.Clear]>) {
return this.on(Events.Clear, handler);
}
}

export const TVSeasonSelect = (props: { store: TVSeasonSelectCore }) => {
Expand All @@ -112,7 +120,7 @@ export const TVSeasonSelect = (props: { store: TVSeasonSelectCore }) => {
setTVListResponse(nextState);
});
store.onCurSeasonChange((nextState) => {
// console.log("[COMPONENT]TVSeasonSelect - store.onCurSeasonChange", nextState);
// console.log("[COMPONENT]TVSeasonSelect - store.onCurSeasonChange", nextState);
setCurSeason(nextState);
});

Expand Down Expand Up @@ -163,7 +171,7 @@ export const TVSeasonSelect = (props: { store: TVSeasonSelectCore }) => {
"border-slate-300 ": curSeason()?.id !== id,
}}
onClick={() => {
// console.log("[COMPONENT]TVSeasonSelect - onClick", season);
// console.log("[COMPONENT]TVSeasonSelect - onClick", season);
store.select(season);
}}
>
Expand Down
26 changes: 14 additions & 12 deletions src/components/ui/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,20 @@ export function Dialog(
</DialogPrimitive.Title>
</DialogPrimitive.Header>
{props.children}
<DialogPrimitive.Close
class={cn(
"absolute top-4 right-4 cursor-pointer rounded-sm",
"opacity-70 transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-slate-400 focus:ring-offset-2 disabled:pointer-events-none",
"dark:focus:ring-slate-400 dark:focus:ring-offset-slate-900",
"data-[state=open]:bg-slate-100 dark:data-[state=open]:bg-slate-800"
)}
store={store}
>
<X width={15} height={15} />
<span class="sr-only">Close</span>
</DialogPrimitive.Close>
<Show when={state().closeable}>
<DialogPrimitive.Close
class={cn(
"absolute top-4 right-4 cursor-pointer rounded-sm",
"opacity-70 transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-slate-400 focus:ring-offset-2 disabled:pointer-events-none",
"dark:focus:ring-slate-400 dark:focus:ring-offset-slate-900",
"data-[state=open]:bg-slate-100 dark:data-[state=open]:bg-slate-800"
)}
store={store}
>
<X width={15} height={15} />
<span class="sr-only">Close</span>
</DialogPrimitive.Close>
</Show>
<Show when={footer()}>
<DialogPrimitive.Footer class="flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2">
<div class="space-x-2">
Expand Down
7 changes: 5 additions & 2 deletions src/domains/list/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,8 +582,11 @@ export class ListCore<
* 手动修改当前 dataSource
* @param fn
*/
modifyDataSource(dataSource: T[]) {
this.response.dataSource = dataSource;
modifyDataSource(fn: (v: T) => T) {
this.response.dataSource = this.response.dataSource.map((item) => {
return fn(item);
});
this.emit(Events.StateChange, { ...this.response });
this.emit(Events.DataSourceChange, [...this.response.dataSource]);
}
/**
Expand Down
14 changes: 12 additions & 2 deletions src/domains/navigator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
*/
import qs from "qs";
import { Handler } from "mitt";
import parse from "url-parse";

import { BaseDomain } from "@/domains/base";
import { JSONObject } from "@/types";
import { query_stringify } from "@/utils";

enum Events {
PushState,
Expand Down Expand Up @@ -80,6 +80,17 @@ type NavigatorState = {

export class NavigatorCore extends BaseDomain<TheTypesOfEvents> {
static prefix: string | null = null;
static parse(url: string) {
const { pathname, ...rest } = parse(url);
if (NavigatorCore.prefix && pathname.startsWith(NavigatorCore.prefix)) {
return { ...rest, pathname: pathname.replace(NavigatorCore.prefix, "") };
}
return {
...rest,
pathname,
};
}

_name = "NavigatorCore";
debug = false;

Expand Down Expand Up @@ -148,7 +159,6 @@ export class NavigatorCore extends BaseDomain<TheTypesOfEvents> {
];
this.emit(Events.PathnameChange, { ...this._pending });
}

private setPrevPathname(p: string) {
this.prevPathname = p;
}
Expand Down
29 changes: 28 additions & 1 deletion src/domains/request/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@ enum Events {
Success,
Failed,
Completed,
StateChange,
ResponseChange,
}
type TheTypesOfEvents<T> = {
type TheTypesOfEvents<T extends (...args: any[]) => Promise<Result<any>>> = {
[Events.LoadingChange]: boolean;
[Events.BeforeRequest]: void;
[Events.AfterRequest]: void;
[Events.Success]: T;
[Events.Failed]: BizError;
[Events.Completed]: void;
[Events.StateChange]: RequestState;
[Events.ResponseChange]: UnpackedResult<Unpacked<ReturnType<T>>> | null;
};
type RequestState = {};
type RequestProps<T> = {
Expand All @@ -45,13 +49,21 @@ export class RequestCore<T extends (...args: any[]) => Promise<Result<any>>> ext
/** 原始 service 函数 */
private _service: T;
delay: null | number = 800;
loading = false;
/** 处于请求中的 promise */
pending: ReturnType<T> | null = null;
/** 调用 prepare 方法暂存的参数 */
args: Parameters<T> | null = null;
/** 请求的响应 */
response: UnpackedResult<Unpacked<ReturnType<T>>> | null = null;

get state(): RequestState {
return {
loading: this.loading,
response: this.response,
};
}

constructor(service: T, props: Partial<RequestProps<UnpackedResult<Unpacked<ReturnType<T>>>>> = {}) {
super();

Expand Down Expand Up @@ -90,11 +102,13 @@ export class RequestCore<T extends (...args: any[]) => Promise<Result<any>>> ext
}
this.args = args;
this.emit(Events.LoadingChange, true);
this.emit(Events.StateChange, { ...this.state });
this.emit(Events.BeforeRequest);
const pending = this._service(...args, this.token) as ReturnType<T>;
this.pending = pending;
const [r] = await Promise.all([pending, this.delay === null ? null : sleep(this.delay)]);
this.emit(Events.LoadingChange, false);
this.emit(Events.StateChange, { ...this.state });
this.emit(Events.Completed);
this.pending = null;
console.log("[DOMAIN]client - run", r.error);
Expand All @@ -105,6 +119,8 @@ export class RequestCore<T extends (...args: any[]) => Promise<Result<any>>> ext
this.response = r.data;
const d = r.data as UnpackedResult<Unpacked<ReturnType<T>>>;
this.emit(Events.Success, d);
this.emit(Events.StateChange, { ...this.state });
this.emit(Events.ResponseChange, this.response);
return Result.Ok(d);
}
/** 使用当前参数再请求一次 */
Expand All @@ -114,6 +130,11 @@ export class RequestCore<T extends (...args: any[]) => Promise<Result<any>>> ext
}
this.run(...this.args);
}
clear() {
this.response = null;
this.emit(Events.StateChange, { ...this.state });
this.emit(Events.ResponseChange, this.response);
}

onLoadingChange(handler: Handler<TheTypesOfEvents<UnpackedResult<Unpacked<ReturnType<T>>>>[Events.LoadingChange]>) {
return this.on(Events.LoadingChange, handler);
Expand All @@ -134,4 +155,10 @@ export class RequestCore<T extends (...args: any[]) => Promise<Result<any>>> ext
onCompleted(handler: Handler<TheTypesOfEvents<UnpackedResult<Unpacked<ReturnType<T>>>>[Events.Completed]>) {
return this.on(Events.Completed, handler);
}
onStateChange(handler: Handler<TheTypesOfEvents<UnpackedResult<Unpacked<ReturnType<T>>>>[Events.StateChange]>) {
return this.on(Events.StateChange, handler);
}
onResponseChange(handler: Handler<TheTypesOfEvents<UnpackedResult<Unpacked<ReturnType<T>>>>[Events.ResponseChange]>) {
return this.on(Events.ResponseChange, handler);
}
}
9 changes: 7 additions & 2 deletions src/domains/route_view/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,13 @@ export class RouteViewCore extends BaseDomain<TheTypesOfEvents> {
}

checkMatchRegexp(url: string) {
const { pathname, query } = parse(url);
console.log(url, pathname);
const pathname = (() => {
if (url.startsWith("http")) {
return parse(url).pathname;
}
return url;
})();
console.log(pathname);
if (pathname === this.key) {
return true;
}
Expand Down
8 changes: 7 additions & 1 deletion src/domains/ui/dialog/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,13 @@ type DialogState = {
open: boolean;
title: string;
footer?: boolean;
/** 能否手动关闭 */
closeable?: boolean;
};
export type DialogProps = {
title?: string;
footer?: boolean;
closeable?: boolean;
onCancel?: () => void;
onOk?: () => void;
onUnmounted?: () => void;
Expand All @@ -51,6 +54,7 @@ export class DialogCore extends BaseDomain<TheTypesOfEvents> {
open = false;
title: string = "";
footer: boolean = true;
closeable: boolean = true;

present = new PresenceCore();
okBtn = new ButtonCore();
Expand All @@ -61,17 +65,19 @@ export class DialogCore extends BaseDomain<TheTypesOfEvents> {
open: this.open,
title: this.title,
footer: this.footer,
closeable: this.closeable,
};
}

constructor(options: Partial<{ _name: string }> & DialogProps = {}) {
super(options);

const { title, footer = true, onOk, onCancel, onUnmounted } = options;
const { title, footer = true, closeable = true, onOk, onCancel, onUnmounted } = options;
if (title) {
this.title = title;
}
this.footer = footer;
this.closeable = closeable;
if (onOk) {
this.onOk(onOk);
}
Expand Down
37 changes: 21 additions & 16 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,42 @@ import { Toast } from "./components/ui/toast";
import { RouteView } from "./components/ui/route-view";
import { connect } from "./domains/app/connect.web";
import { ToastCore } from "./domains/ui/toast";
import { rootView, homeIndexPage, homeLayout } from "./store/views";
import { NavigatorCore } from "./domains/navigator";
import { rootView, homeIndexPage } from "./store/views";
import { app, router, initializeJobs, pages } from "./store";
import { sleep } from "./utils";

import "./style.css";

app.onClickLink(({ href }) => {
console.log(href);
// router.push(href);
const { pathname } = NavigatorCore.parse(href);
const matched = pages.find((v) => {
return v.key === pathname;
});
if (matched) {
matched.query = router.query;
app.showView(matched);
return;
}
app.tip({
text: ["没有匹配的页面"],
});
// app.showView(homeIndexPage);
});
app.onPopState((options) => {
const { type, pathname } = options;
console.log("[]index.tsx - app.onPopState", type, pathname);
// router.handlePopState({ type, pathname });
const { pathname } = NavigatorCore.parse(options.pathname);
const matched = pages.find((v) => {
return v.checkMatchRegexp(pathname);
return v.key === pathname;
});
// console.log(router.pathname, matched);
if (matched) {
matched.isShowForBack = true;
matched.query = router.query;
app.showView(matched);
return;
}
homeIndexPage.isShowForBack = true;
app.showView(homeIndexPage);
});
// router.onBack(() => {
// homeLayout.showPrevView({ ignore: true });
// });
// router.onHistoriesChange((histories) => {
// console.log(histories.map((h) => h.pathname));
// });
connect(app);

function Application() {
Expand Down Expand Up @@ -86,10 +91,10 @@ function Application() {
const { innerWidth, innerHeight, location } = window;
router.prepare(location);
(() => {
const { pathname } = NavigatorCore.parse(router.pathname);
const matched = pages.find((v) => {
return v.checkMatchRegexp(router.pathname);
return v.key === pathname;
});
console.log(router.pathname, matched);
if (matched) {
matched.query = router.query;
app.showView(matched);
Expand Down
3 changes: 3 additions & 0 deletions src/packages/ui/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ const Overlay = (props: { store: DialogCore } & JSX.HTMLAttributes<HTMLDivElemen
data-state={getState(state().open)}
class={cn(props.class)}
onClick={() => {
if (!store.closeable) {
return;
}
store.hide();
}}
/>
Expand Down
Loading

0 comments on commit 85a4305

Please sign in to comment.