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
baichixing
Neos
Commits
e8fc6fda
Commit
e8fc6fda
authored
Aug 20, 2023
by
timel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: async to sync
parent
ca83bae4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
15 deletions
+19
-15
src/api/cards.ts
src/api/cards.ts
+4
-4
src/middleware/sqlite/index.ts
src/middleware/sqlite/index.ts
+14
-10
src/ui/BuildDeck/CardDetail.tsx
src/ui/BuildDeck/CardDetail.tsx
+1
-1
No files found.
src/api/cards.ts
View file @
e8fc6fda
...
...
@@ -50,8 +50,8 @@ export interface CardText {
* @returns 卡片数据
*
* */
export
async
function
fetchCard
(
id
:
number
):
Promise
<
CardMeta
>
{
const
res
=
await
sqliteMiddleWare
({
export
function
fetchCard
(
id
:
number
):
CardMeta
{
const
res
=
sqliteMiddleWare
({
cmd
:
sqliteCmd
.
SELECT
,
payload
:
{
id
},
});
...
...
@@ -65,8 +65,8 @@ export async function fetchCard(id: number): Promise<CardMeta> {
* @returns 卡片数据
*
* */
export
async
function
searchCards
(
params
:
FtsParams
):
Promise
<
CardMeta
[]
>
{
const
res
=
await
sqliteMiddleWare
({
export
function
searchCards
(
params
:
FtsParams
):
CardMeta
[]
{
const
res
=
sqliteMiddleWare
({
cmd
:
sqliteCmd
.
FTS
,
payload
:
{
ftsParams
:
params
},
});
...
...
src/middleware/sqlite/index.ts
View file @
e8fc6fda
...
...
@@ -24,8 +24,8 @@ export enum sqliteCmd {
FTS
,
}
export
interface
sqliteAction
{
cmd
:
sqliteCmd
;
export
interface
sqliteAction
<
T
extends
sqliteCmd
>
{
cmd
:
T
;
// 初始化DB需要业务方传入的数据
initInfo
?:
{
dbUrl
:
string
;
...
...
@@ -47,8 +47,14 @@ const sqlPromise = initSqlJs({
locateFile
:
(
file
)
=>
`
${
NeosConfig
.
assetsPath
}
/
${
file
}
`
,
});
export
default
function
<
T
extends
sqliteCmd
>
(
action
:
sqliteAction
<
T
>
,
):
T
extends
sqliteCmd
.
INIT
?
Promise
<
void
>
:
sqliteResult
{
return
helper
(
action
)
as
any
;
}
// FIXME: 应该有个返回值,告诉业务方本次请求的结果,比如初始化DB失败
export
default
async
function
(
action
:
sqliteAction
):
Promise
<
sqliteResult
>
{
function
helper
<
T
extends
sqliteCmd
>
(
action
:
sqliteAction
<
T
>
)
{
switch
(
action
.
cmd
)
{
case
sqliteCmd
.
INIT
:
{
const
info
=
action
.
initInfo
;
...
...
@@ -56,16 +62,14 @@ export default async function (action: sqliteAction): Promise<sqliteResult> {
const
dataPromise
=
pfetch
(
info
.
dbUrl
,
{
progressCallback
:
action
.
initInfo
?.
progressCallback
,
}).
then
((
res
)
=>
res
.
arrayBuffer
());
// TODO: i18n
const
[
SQL
,
buffer
]
=
await
Promise
.
all
([
sqlPromise
,
dataPromise
]);
YGODB
=
new
SQL
.
Database
(
new
Uint8Array
(
buffer
));
console
.
info
(
"
YGODB inited!
"
);
return
Promise
.
all
([
sqlPromise
,
dataPromise
]).
then
(([
SQL
,
buffer
])
=>
{
YGODB
=
new
SQL
.
Database
(
new
Uint8Array
(
buffer
));
console
.
log
(
"
YGODB inited!
"
);
});
}
else
{
console
.
warn
(
"
init YGODB action without initInfo
"
);
return
{};
}
return
{};
}
case
sqliteCmd
.
SELECT
:
{
if
(
YGODB
&&
action
.
payload
&&
action
.
payload
.
id
)
{
...
...
src/ui/BuildDeck/CardDetail.tsx
View file @
e8fc6fda
...
...
@@ -23,7 +23,7 @@ export const CardDetail: React.FC<{
}
>
=
({
code
,
open
,
onClose
})
=>
{
const
[
card
,
setCard
]
=
useState
<
CardMeta
>
();
useEffect
(()
=>
{
fetchCard
(
code
).
then
(
setCard
);
setCard
(
fetchCard
(
code
)
);
},
[
code
]);
const
cardType
=
useMemo
(
()
=>
...
...
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