Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
d5f874e1
Commit
d5f874e1
authored
Jan 20, 2024
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: handle resource not found
parent
89d940d9
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
4 deletions
+18
-4
resource_service.go
api/v2/resource_service.go
+3
-0
EmbeddedMemo.tsx
...c/components/MemoContent/EmbeddedContent/EmbeddedMemo.tsx
+7
-2
EmbeddedResource.tsx
...mponents/MemoContent/EmbeddedContent/EmbeddedResource.tsx
+8
-2
No files found.
api/v2/resource_service.go
View file @
d5f874e1
...
...
@@ -73,6 +73,9 @@ func (s *APIV2Service) GetResource(ctx context.Context, request *apiv2pb.GetReso
if
err
!=
nil
{
return
nil
,
status
.
Errorf
(
codes
.
Internal
,
"failed to list resources: %v"
,
err
)
}
if
resource
==
nil
{
return
nil
,
status
.
Errorf
(
codes
.
NotFound
,
"resource not found"
)
}
return
&
apiv2pb
.
GetResourceResponse
{
Resource
:
s
.
convertResourceFromStore
(
ctx
,
resource
),
...
...
web/src/components/MemoContent/EmbeddedContent/EmbeddedMemo.tsx
View file @
d5f874e1
import
{
useContext
,
useEffect
}
from
"react"
;
import
useLoading
from
"@/hooks/useLoading"
;
import
{
useMemoStore
}
from
"@/store/v1"
;
import
MemoContent
from
".."
;
import
{
RendererContext
}
from
"../types"
;
...
...
@@ -11,17 +12,21 @@ interface Props {
const
EmbeddedMemo
=
({
memoId
}:
Props
)
=>
{
const
context
=
useContext
(
RendererContext
);
const
loadingState
=
useLoading
();
const
memoStore
=
useMemoStore
();
const
memo
=
memoStore
.
getMemoById
(
memoId
);
const
resourceName
=
`memos/
${
memoId
}
`
;
useEffect
(()
=>
{
memoStore
.
getOrFetchMemoById
(
memoId
);
memoStore
.
getOrFetchMemoById
(
memoId
)
.
finally
(()
=>
loadingState
.
setFinish
())
;
},
[
memoId
]);
if
(
!
memo
)
{
if
(
loadingState
.
isLoading
)
{
return
null
;
}
if
(
!
memo
)
{
return
<
Error
message=
{
`Memo not found: ${memoId}`
}
/>;
}
if
(
memoId
===
context
.
memoId
||
context
.
embeddedMemos
.
has
(
resourceName
))
{
return
<
Error
message=
{
`Nested Rendering Error: ![[${resourceName}]]`
}
/>;
}
...
...
web/src/components/MemoContent/EmbeddedContent/EmbeddedResource.tsx
View file @
d5f874e1
import
classNames
from
"classnames"
;
import
{
useEffect
}
from
"react"
;
import
MemoResourceListView
from
"@/components/MemoResourceListView"
;
import
useLoading
from
"@/hooks/useLoading"
;
import
{
useResourceStore
}
from
"@/store/v1"
;
import
Error
from
"./Error"
;
interface
Props
{
resourceId
:
number
;
...
...
@@ -34,17 +36,21 @@ const getAdditionalClassNameWithParams = (params: URLSearchParams) => {
};
const
EmbeddedResource
=
({
resourceId
,
params
:
paramsStr
}:
Props
)
=>
{
const
loadingState
=
useLoading
();
const
resourceStore
=
useResourceStore
();
const
resource
=
resourceStore
.
getResourceById
(
resourceId
);
const
params
=
new
URLSearchParams
(
paramsStr
);
useEffect
(()
=>
{
resourceStore
.
getOrFetchResourceById
(
resourceId
);
resourceStore
.
getOrFetchResourceById
(
resourceId
)
.
finally
(()
=>
loadingState
.
setFinish
())
;
},
[
resourceId
]);
if
(
!
resource
)
{
if
(
loadingState
.
isLoading
)
{
return
null
;
}
if
(
!
resource
)
{
return
<
Error
message=
{
`Resource not found: ${resourceId}`
}
/>;
}
return
(
<
div
className=
{
classNames
(
"max-w-full"
,
getAdditionalClassNameWithParams
(
params
))
}
>
...
...
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