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
2837816f
Commit
2837816f
authored
Sep 25, 2024
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: fix component state
parent
b144faf4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
25 deletions
+32
-25
memo_service.go
server/router/api/v1/memo_service.go
+3
-2
LocationSelector.tsx
...c/components/MemoEditor/ActionButton/LocationSelector.tsx
+28
-8
index.tsx
web/src/components/MemoEditor/index.tsx
+1
-15
No files found.
server/router/api/v1/memo_service.go
View file @
2837816f
...
@@ -331,8 +331,9 @@ func (s *APIV1Service) UpdateMemo(ctx context.Context, request *v1pb.UpdateMemoR
...
@@ -331,8 +331,9 @@ func (s *APIV1Service) UpdateMemo(ctx context.Context, request *v1pb.UpdateMemoR
return
nil
,
errors
.
Wrap
(
err
,
"failed to set memo relations"
)
return
nil
,
errors
.
Wrap
(
err
,
"failed to set memo relations"
)
}
}
}
else
if
path
==
"location"
{
}
else
if
path
==
"location"
{
memo
.
Payload
.
Location
=
convertLocationToStore
(
request
.
Memo
.
Location
)
payload
:=
memo
.
Payload
update
.
Payload
=
memo
.
Payload
payload
.
Location
=
convertLocationToStore
(
request
.
Memo
.
Location
)
update
.
Payload
=
payload
}
}
}
}
...
...
web/src/components/MemoEditor/ActionButton/LocationSelector.tsx
View file @
2837816f
import
{
Button
,
IconButton
,
Input
}
from
"@mui/joy"
;
import
{
Button
,
IconButton
,
Input
}
from
"@mui/joy"
;
import
{
LatLng
}
from
"leaflet"
;
import
{
LatLng
}
from
"leaflet"
;
import
{
MapPinIcon
}
from
"lucide-react"
;
import
{
MapPinIcon
,
XIcon
}
from
"lucide-react"
;
import
{
useEffect
,
useState
}
from
"react"
;
import
{
useEffect
,
useState
}
from
"react"
;
import
toast
from
"react-hot-toast"
;
import
toast
from
"react-hot-toast"
;
import
LeafletMap
from
"@/components/LeafletMap"
;
import
LeafletMap
from
"@/components/LeafletMap"
;
...
@@ -10,10 +10,11 @@ import { useTranslate } from "@/utils/i18n";
...
@@ -10,10 +10,11 @@ import { useTranslate } from "@/utils/i18n";
interface
Props
{
interface
Props
{
location
?:
Location
;
location
?:
Location
;
onChange
:
(
location
:
Location
)
=>
void
;
onChange
:
(
location
?
:
Location
)
=>
void
;
}
}
interface
State
{
interface
State
{
initilized
:
boolean
;
placeholder
:
string
;
placeholder
:
string
;
position
:
LatLng
;
position
:
LatLng
;
}
}
...
@@ -21,14 +22,24 @@ interface State {
...
@@ -21,14 +22,24 @@ interface State {
const
LocationSelector
=
(
props
:
Props
)
=>
{
const
LocationSelector
=
(
props
:
Props
)
=>
{
const
t
=
useTranslate
();
const
t
=
useTranslate
();
const
[
state
,
setState
]
=
useState
<
State
>
({
const
[
state
,
setState
]
=
useState
<
State
>
({
initilized
:
false
,
placeholder
:
props
.
location
?.
placeholder
||
""
,
placeholder
:
props
.
location
?.
placeholder
||
""
,
position
:
new
LatLng
(
props
.
location
?.
latitude
||
0
,
props
.
location
?.
longitude
||
0
),
position
:
new
LatLng
(
props
.
location
?.
latitude
||
0
,
props
.
location
?.
longitude
||
0
),
});
});
const
[
popoverOpen
,
setPopoverOpen
]
=
useState
<
boolean
>
(
false
);
const
[
popoverOpen
,
setPopoverOpen
]
=
useState
<
boolean
>
(
false
);
useEffect
(()
=>
{
setState
((
state
)
=>
({
...
state
,
placeholder
:
props
.
location
?.
placeholder
||
""
,
position
:
new
LatLng
(
props
.
location
?.
latitude
||
0
,
props
.
location
?.
longitude
||
0
),
}));
},
[
props
.
location
]);
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
popoverOpen
&&
!
props
.
location
)
{
if
(
popoverOpen
&&
!
props
.
location
)
{
const
handleError
=
(
error
:
any
,
errorMessage
:
string
)
=>
{
const
handleError
=
(
error
:
any
,
errorMessage
:
string
)
=>
{
setState
({
...
state
,
initilized
:
true
});
toast
.
error
(
errorMessage
);
toast
.
error
(
errorMessage
);
console
.
error
(
error
);
console
.
error
(
error
);
};
};
...
@@ -38,7 +49,7 @@ const LocationSelector = (props: Props) => {
...
@@ -38,7 +49,7 @@ const LocationSelector = (props: Props) => {
(
position
)
=>
{
(
position
)
=>
{
const
lat
=
position
.
coords
.
latitude
;
const
lat
=
position
.
coords
.
latitude
;
const
lng
=
position
.
coords
.
longitude
;
const
lng
=
position
.
coords
.
longitude
;
setState
({
...
state
,
position
:
new
LatLng
(
lat
,
lng
)
});
setState
({
...
state
,
position
:
new
LatLng
(
lat
,
lng
)
,
initilized
:
true
});
},
},
(
error
)
=>
{
(
error
)
=>
{
handleError
(
error
,
"Error getting current position"
);
handleError
(
error
,
"Error getting current position"
);
...
@@ -69,21 +80,30 @@ const LocationSelector = (props: Props) => {
...
@@ -69,21 +80,30 @@ const LocationSelector = (props: Props) => {
setState
({
...
state
,
position
});
setState
({
...
state
,
position
});
};
};
const
removeLocation
=
(
e
:
React
.
MouseEvent
)
=>
{
e
.
preventDefault
();
e
.
stopPropagation
();
props
.
onChange
(
undefined
);
};
return
(
return
(
<
Popover
open=
{
popoverOpen
}
onOpenChange=
{
setPopoverOpen
}
>
<
Popover
open=
{
popoverOpen
}
onOpenChange=
{
setPopoverOpen
}
>
<
PopoverTrigger
>
<
PopoverTrigger
>
<
IconButton
size=
"sm"
component=
"div"
>
<
IconButton
className=
"group"
size=
"sm"
component=
"div"
>
<
MapPinIcon
className=
"w-5 h-5 mx-auto shrink-0"
/>
<
MapPinIcon
className=
"w-5 h-5 mx-auto shrink-0"
/>
{
props
.
location
&&
(
{
props
.
location
&&
(
<
span
className=
"font-normal ml-0.5 text-ellipsis whitespace-nowrap overflow-hidden max-w-32"
>
<>
{
props
.
location
.
placeholder
}
<
span
className=
"font-normal ml-0.5 text-ellipsis whitespace-nowrap overflow-hidden max-w-32"
>
</
span
>
{
props
.
location
.
placeholder
}
</
span
>
<
XIcon
className=
"w-5 h-5 mx-auto shrink-0 hidden group-hover:block hover:opacity-80"
onClick=
{
removeLocation
}
/>
</>
)
}
)
}
</
IconButton
>
</
IconButton
>
</
PopoverTrigger
>
</
PopoverTrigger
>
<
PopoverContent
align=
"center"
>
<
PopoverContent
align=
"center"
>
<
div
className=
"min-w-80 sm:w-128 flex flex-col justify-start items-start"
>
<
div
className=
"min-w-80 sm:w-128 flex flex-col justify-start items-start"
>
<
LeafletMap
key=
{
JSON
.
stringify
(
state
.
position
)
}
latlng=
{
state
.
position
}
onChange=
{
onPositionChanged
}
/>
<
LeafletMap
key=
{
JSON
.
stringify
(
state
.
initilized
)
}
latlng=
{
state
.
position
}
onChange=
{
onPositionChanged
}
/>
<
div
className=
"mt-2 w-full flex flex-row justify-between items-center gap-2"
>
<
div
className=
"mt-2 w-full flex flex-row justify-between items-center gap-2"
>
<
Input
<
Input
placeholder=
"Choose location"
placeholder=
"Choose location"
...
...
web/src/components/MemoEditor/index.tsx
View file @
2837816f
...
@@ -45,7 +45,6 @@ export interface Props {
...
@@ -45,7 +45,6 @@ export interface Props {
}
}
interface
State
{
interface
State
{
initialized
:
boolean
;
memoVisibility
:
Visibility
;
memoVisibility
:
Visibility
;
resourceList
:
Resource
[];
resourceList
:
Resource
[];
relationList
:
MemoRelation
[];
relationList
:
MemoRelation
[];
...
@@ -65,7 +64,6 @@ const MemoEditor = (props: Props) => {
...
@@ -65,7 +64,6 @@ const MemoEditor = (props: Props) => {
const
resourceStore
=
useResourceStore
();
const
resourceStore
=
useResourceStore
();
const
currentUser
=
useCurrentUser
();
const
currentUser
=
useCurrentUser
();
const
[
state
,
setState
]
=
useState
<
State
>
({
const
[
state
,
setState
]
=
useState
<
State
>
({
initialized
:
false
,
memoVisibility
:
Visibility
.
PRIVATE
,
memoVisibility
:
Visibility
.
PRIVATE
,
resourceList
:
[],
resourceList
:
[],
relationList
:
[],
relationList
:
[],
...
@@ -112,16 +110,13 @@ const MemoEditor = (props: Props) => {
...
@@ -112,16 +110,13 @@ const MemoEditor = (props: Props) => {
useAsyncEffect
(
async
()
=>
{
useAsyncEffect
(
async
()
=>
{
if
(
!
memoName
)
{
if
(
!
memoName
)
{
setState
((
prevState
)
=>
({
...
prevState
,
initialized
:
true
,
}));
return
;
return
;
}
}
const
memo
=
await
memoStore
.
getOrFetchMemoByName
(
memoName
);
const
memo
=
await
memoStore
.
getOrFetchMemoByName
(
memoName
);
if
(
memo
)
{
if
(
memo
)
{
handleEditorFocus
();
handleEditorFocus
();
setDisplayTime
(
memo
.
displayTime
);
setState
((
prevState
)
=>
({
setState
((
prevState
)
=>
({
...
prevState
,
...
prevState
,
memoVisibility
:
memo
.
visibility
,
memoVisibility
:
memo
.
visibility
,
...
@@ -129,14 +124,9 @@ const MemoEditor = (props: Props) => {
...
@@ -129,14 +124,9 @@ const MemoEditor = (props: Props) => {
relationList
:
memo
.
relations
,
relationList
:
memo
.
relations
,
location
:
memo
.
location
,
location
:
memo
.
location
,
}));
}));
setDisplayTime
(
memo
.
displayTime
);
if
(
!
contentCache
)
{
if
(
!
contentCache
)
{
editorRef
.
current
?.
setContent
(
memo
.
content
??
""
);
editorRef
.
current
?.
setContent
(
memo
.
content
??
""
);
}
}
setState
((
prevState
)
=>
({
...
prevState
,
initialized
:
true
,
}));
}
}
},
[
memoName
]);
},
[
memoName
]);
...
@@ -403,10 +393,6 @@ const MemoEditor = (props: Props) => {
...
@@ -403,10 +393,6 @@ const MemoEditor = (props: Props) => {
const
allowSave
=
(
hasContent
||
state
.
resourceList
.
length
>
0
)
&&
!
state
.
isUploadingResource
&&
!
state
.
isRequesting
;
const
allowSave
=
(
hasContent
||
state
.
resourceList
.
length
>
0
)
&&
!
state
.
isUploadingResource
&&
!
state
.
isRequesting
;
if
(
!
state
.
initialized
)
{
return
null
;
}
return
(
return
(
<
MemoEditorContext
.
Provider
<
MemoEditorContext
.
Provider
value=
{
{
value=
{
{
...
...
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