Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
N
Neos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
love_飞影
Neos
Commits
479b78a7
Commit
479b78a7
authored
Aug 08, 2023
by
timel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: remove suspence
parent
990ac633
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
37 additions
and
40 deletions
+37
-40
src/api/cards.ts
src/api/cards.ts
+0
-4
src/stores/initStore.ts
src/stores/initStore.ts
+3
-5
src/ui/BuildDeck/index.tsx
src/ui/BuildDeck/index.tsx
+19
-27
src/ui/Layout/index.tsx
src/ui/Layout/index.tsx
+8
-2
src/ui/Layout/utils.ts
src/ui/Layout/utils.ts
+7
-2
No files found.
src/api/cards.ts
View file @
479b78a7
...
@@ -67,10 +67,6 @@ export async function searchCard(
...
@@ -67,10 +67,6 @@ export async function searchCard(
type
?:
number
type
?:
number
):
Promise
<
CardMeta
[]
>
{
):
Promise
<
CardMeta
[]
>
{
// TODO: 让type支持多种filter类型
// TODO: 让type支持多种filter类型
console
.
log
({
cmd
:
sqliteCmd
.
FTS
,
payload
:
{
query
,
type
},
});
const
res
=
await
sqliteMiddleWare
({
const
res
=
await
sqliteMiddleWare
({
cmd
:
sqliteCmd
.
FTS
,
cmd
:
sqliteCmd
.
FTS
,
payload
:
{
query
,
type
},
payload
:
{
query
,
type
},
...
...
src/stores/initStore.ts
View file @
479b78a7
...
@@ -4,12 +4,10 @@ import { type NeosStore } from "./shared";
...
@@ -4,12 +4,10 @@ import { type NeosStore } from "./shared";
export
const
initStore
=
proxy
({
export
const
initStore
=
proxy
({
sqlite
:
{
sqlite
:
{
initialized
:
false
,
progress
:
0
,
// 0 -> 1
progress
:
0
,
},
i18n
:
{
initialized
:
false
,
},
},
decks
:
false
,
i18n
:
false
,
// ...
// ...
reset
()
{},
reset
()
{},
}
satisfies
NeosStore
);
}
satisfies
NeosStore
);
src/ui/BuildDeck/index.tsx
View file @
479b78a7
...
@@ -15,14 +15,9 @@ import {
...
@@ -15,14 +15,9 @@ import {
Space
,
Space
,
type
ThemeConfig
,
type
ThemeConfig
,
}
from
"
antd
"
;
}
from
"
antd
"
;
import
{
Suspense
,
useEffect
,
useState
}
from
"
react
"
;
import
{
useEffect
,
useState
}
from
"
react
"
;
import
{
Await
,
defer
,
type
LoaderFunction
,
useLoaderData
,
}
from
"
react-router-dom
"
;
import
{
useSnapshot
}
from
"
valtio
"
;
import
{
useSnapshot
}
from
"
valtio
"
;
import
{
subscribeKey
}
from
"
valtio/utils
"
;
import
{
deckStore
,
type
IDeck
,
initStore
}
from
"
@/stores
"
;
import
{
deckStore
,
type
IDeck
,
initStore
}
from
"
@/stores
"
;
import
{
Background
,
Loading
,
ScrollableArea
,
YgoCard
}
from
"
@/ui/Shared
"
;
import
{
Background
,
Loading
,
ScrollableArea
,
YgoCard
}
from
"
@/ui/Shared
"
;
...
@@ -30,7 +25,7 @@ import { Background, Loading, ScrollableArea, YgoCard } from "@/ui/Shared";
...
@@ -30,7 +25,7 @@ import { Background, Loading, ScrollableArea, YgoCard } from "@/ui/Shared";
import
{
CardDetail
}
from
"
./CardDetail
"
;
import
{
CardDetail
}
from
"
./CardDetail
"
;
import
{
DeckSelect
}
from
"
./DeckSelect
"
;
import
{
DeckSelect
}
from
"
./DeckSelect
"
;
import
styles
from
"
./index.module.scss
"
;
import
styles
from
"
./index.module.scss
"
;
import
{
initSqlite
}
from
"
./utils
"
;
import
{
LoaderFunction
}
from
"
react-router-dom
"
;
const
theme
:
ThemeConfig
=
{
const
theme
:
ThemeConfig
=
{
components
:
{
components
:
{
...
@@ -41,18 +36,18 @@ const theme: ThemeConfig = {
...
@@ -41,18 +36,18 @@ const theme: ThemeConfig = {
};
};
export
const
loader
:
LoaderFunction
=
async
()
=>
{
export
const
loader
:
LoaderFunction
=
async
()
=>
{
return
defer
({
// 必须先加载卡组,不然页面会崩溃
initialized
:
initStore
.
sqlite
.
initialized
if
(
!
initStore
.
decks
)
{
?
true
await
new
Promise
<
void
>
((
rs
)
=>
{
:
initSqlite
().
then
(()
=>
(
initStore
.
sqlite
.
initialized
=
true
)),
subscribeKey
(
initStore
,
"
decks
"
,
(
done
)
=>
done
&&
rs
());
});
});
}
return
null
;
};
};
export
const
Component
:
React
.
FC
=
()
=>
{
export
const
Component
:
React
.
FC
=
()
=>
{
const
data
=
useLoaderData
<
{
initialized
:
boolean
;
}
>
();
const
snapDecks
=
useSnapshot
(
deckStore
);
const
snapDecks
=
useSnapshot
(
deckStore
);
const
{
sqlite
}
=
useSnapshot
(
initStore
);
const
[
selectedDeck
,
setSelectedDeck
]
=
useState
<
IDeck
>
(
deckStore
.
decks
[
0
]);
const
[
selectedDeck
,
setSelectedDeck
]
=
useState
<
IDeck
>
(
deckStore
.
decks
[
0
]);
return
(
return
(
...
@@ -79,17 +74,13 @@ export const Component: React.FC = () => {
...
@@ -79,17 +74,13 @@ export const Component: React.FC = () => {
<
DeckEditor
deck=
{
selectedDeck
}
onSave=
{
()
=>
{}
}
/>
<
DeckEditor
deck=
{
selectedDeck
}
onSave=
{
()
=>
{}
}
/>
</
div
>
</
div
>
<
div
className=
{
styles
.
select
}
>
<
div
className=
{
styles
.
select
}
>
<
Suspense
{
sqlite
.
progress
===
1
?
(
fallback=
{
<
CardSelect
/>
)
:
(
<
div
className=
{
styles
.
container
}
>
<
div
className=
{
styles
.
container
}
>
<
Loading
/>
<
Loading
/>
</
div
>
</
div
>
}
)
}
>
<
Await
resolve=
{
data
.
initialized
}
>
<
CardSelect
/>
</
Await
>
</
Suspense
>
</
div
>
</
div
>
</
div
>
</
div
>
</
div
>
</
div
>
...
@@ -156,6 +147,7 @@ const DeckEditor: React.FC<{
...
@@ -156,6 +147,7 @@ const DeckEditor: React.FC<{
/** 卡片库,选择卡片加入正在编辑的卡组 */
/** 卡片库,选择卡片加入正在编辑的卡组 */
const
CardSelect
:
React
.
FC
=
()
=>
{
const
CardSelect
:
React
.
FC
=
()
=>
{
const
[
searchResult
,
setSearchResult
]
=
useState
<
number
[]
>
([]);
return
(
return
(
<
div
className=
{
styles
.
container
}
>
<
div
className=
{
styles
.
container
}
>
<
div
className=
{
styles
.
title
}
>
<
div
className=
{
styles
.
title
}
>
...
...
src/ui/Layout/index.tsx
View file @
479b78a7
...
@@ -9,16 +9,22 @@ import { useSnapshot } from "valtio";
...
@@ -9,16 +9,22 @@ import { useSnapshot } from "valtio";
import
{
CookieKeys
,
getCookie
}
from
"
@/api
"
;
import
{
CookieKeys
,
getCookie
}
from
"
@/api
"
;
import
{
useConfig
}
from
"
@/config
"
;
import
{
useConfig
}
from
"
@/config
"
;
import
{
accountStore
,
deckStore
,
type
User
}
from
"
@/stores
"
;
import
{
accountStore
,
deckStore
,
type
User
,
initStore
}
from
"
@/stores
"
;
import
styles
from
"
./index.module.scss
"
;
import
styles
from
"
./index.module.scss
"
;
import
{
initSqlite
}
from
"
./utils
"
;
const
NeosConfig
=
useConfig
();
const
NeosConfig
=
useConfig
();
export
const
loader
:
LoaderFunction
=
async
()
=>
{
export
const
loader
:
LoaderFunction
=
async
()
=>
{
const
user
=
getCookie
<
User
>
(
CookieKeys
.
USER
);
const
user
=
getCookie
<
User
>
(
CookieKeys
.
USER
);
if
(
user
)
accountStore
.
login
(
user
);
if
(
user
)
accountStore
.
login
(
user
);
await
deckStore
.
initialize
();
// 加载卡组
deckStore
.
initialize
().
then
(()
=>
(
initStore
.
decks
=
true
));
// 加载ygodb
initSqlite
().
then
(()
=>
(
initStore
.
sqlite
.
progress
=
1
));
initStore
.
sqlite
.
progress
=
0.01
;
return
null
;
return
null
;
};
};
...
...
src/ui/
BuildDeck
/utils.ts
→
src/ui/
Layout
/utils.ts
View file @
479b78a7
import
{
useConfig
}
from
"
@/config
"
;
import
{
useConfig
}
from
"
@/config
"
;
import
sqliteMiddleWare
,
{
sqliteCmd
}
from
"
@/middleware/sqlite
"
;
import
sqliteMiddleWare
,
{
sqliteCmd
}
from
"
@/middleware/sqlite
"
;
import
{
initStore
}
from
"
@/stores
"
;
const
{
cardsDbUrl
}
=
useConfig
();
const
{
cardsDbUrl
}
=
useConfig
();
export
const
initSqlite
=
()
=>
export
const
initSqlite
=
async
()
=>
{
sqliteMiddleWare
({
const
{
sqlite
}
=
initStore
;
sqlite
.
progress
=
0.01
;
await
sqliteMiddleWare
({
cmd
:
sqliteCmd
.
INIT
,
cmd
:
sqliteCmd
.
INIT
,
initInfo
:
{
dbUrl
:
cardsDbUrl
},
initInfo
:
{
dbUrl
:
cardsDbUrl
},
});
});
sqlite
.
progress
=
1
;
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment