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
647602be
Commit
647602be
authored
Apr 25, 2024
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: update link preview
parent
81d24f32
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
20 deletions
+25
-20
Link.tsx
web/src/components/MemoContent/Link.tsx
+25
-20
No files found.
web/src/components/MemoContent/Link.tsx
View file @
647602be
import
{
Link
as
MLink
,
Tooltip
}
from
"@mui/joy"
;
import
{
Link
as
MLink
,
Tooltip
}
from
"@mui/joy"
;
import
{
use
Effect
,
use
State
}
from
"react"
;
import
{
useState
}
from
"react"
;
import
{
linkServiceClient
}
from
"@/grpcweb"
;
import
{
linkServiceClient
}
from
"@/grpcweb"
;
import
{
LinkMetadata
}
from
"@/types/proto/api/v2/link_service"
;
import
{
LinkMetadata
}
from
"@/types/proto/api/v2/link_service"
;
...
@@ -18,43 +18,48 @@ const getFaviconWithGoogleS2 = (url: string) => {
...
@@ -18,43 +18,48 @@ const getFaviconWithGoogleS2 = (url: string) => {
};
};
const
Link
:
React
.
FC
<
Props
>
=
({
text
,
url
}:
Props
)
=>
{
const
Link
:
React
.
FC
<
Props
>
=
({
text
,
url
}:
Props
)
=>
{
const
[
initialized
,
setInitialized
]
=
useState
<
boolean
>
(
false
);
const
[
showTooltip
,
setShowTooltip
]
=
useState
<
boolean
>
(
false
);
const
[
linkMetadata
,
setLinkMetadata
]
=
useState
<
LinkMetadata
|
undefined
>
();
const
[
linkMetadata
,
setLinkMetadata
]
=
useState
<
LinkMetadata
|
undefined
>
();
useEffect
(
()
=>
{
const
handleMouseEnter
=
async
()
=>
{
(
async
()
=>
{
if
(
!
initialized
)
{
try
{
try
{
const
{
linkMetadata
}
=
await
linkServiceClient
.
getLinkMetadata
({
link
:
url
},
{});
const
{
linkMetadata
}
=
await
linkServiceClient
.
getLinkMetadata
({
link
:
url
},
{});
setLinkMetadata
(
linkMetadata
);
setLinkMetadata
(
linkMetadata
);
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
error
(
"Error fetching URL metadata:"
,
error
);
console
.
error
(
"Error fetching URL metadata:"
,
error
);
}
}
})();
setInitialized
(
true
);
},
[
url
]);
}
setTimeout
(()
=>
setShowTooltip
(
true
),
0
);
};
return
linkMetadata
?
(
return
(
<
Tooltip
<
Tooltip
variant=
"outlined"
variant=
"outlined"
title=
{
title=
{
linkMetadata
&&
(
<
div
className=
"w-full max-w-64 sm:max-w-96 p-1 flex flex-col"
>
<
div
className=
"w-full max-w-64 sm:max-w-96 p-1 flex flex-col"
>
<
a
href=
{
url
}
target=
"_blank"
rel=
"noopener noreferrer"
className=
"group
w-full flex flex-row justify-start items-center gap-1"
>
<
div
className=
"
w-full flex flex-row justify-start items-center gap-1"
>
<
img
className=
"w-5 h-5 pointer-events-none
"
src=
{
getFaviconWithGoogleS2
(
url
)
}
alt=
{
linkMetadata
?.
title
}
/>
<
img
className=
"w-5 h-5 rounded
"
src=
{
getFaviconWithGoogleS2
(
url
)
}
alt=
{
linkMetadata
?.
title
}
/>
<
h3
className=
"text-base truncate dark:opacity-90 group-hover:opacity-80 group-hover:underline
"
>
{
linkMetadata
?.
title
}
</
h3
>
<
h3
className=
"text-base truncate dark:opacity-90
"
>
{
linkMetadata
?.
title
}
</
h3
>
</
a
>
</
div
>
{
linkMetadata
.
description
&&
(
{
linkMetadata
.
description
&&
(
<
p
className=
"mt-1 w-full text-sm leading-snug opacity-80 line-clamp-3"
>
{
linkMetadata
.
description
}
</
p
>
<
p
className=
"mt-1 w-full text-sm leading-snug opacity-80 line-clamp-3"
>
{
linkMetadata
.
description
}
</
p
>
)
}
)
}
</
div
>
</
div
>
)
}
}
open=
{
showTooltip
}
arrow
arrow
>
>
<
MLink
underline=
"always"
target=
"_blank"
href=
{
url
}
>
<
MLink
underline=
"always"
target=
"_blank"
href=
{
url
}
>
<
span
onMouseEnter=
{
handleMouseEnter
}
onMouseLeave=
{
()
=>
setShowTooltip
(
false
)
}
>
{
text
||
url
}
{
text
||
url
}
</
span
>
</
MLink
>
</
MLink
>
</
Tooltip
>
</
Tooltip
>
)
:
(
<
MLink
underline=
"always"
target=
"_blank"
href=
{
url
}
>
{
text
||
url
}
</
MLink
>
);
);
};
};
...
...
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