mirror of
https://github.com/linsa-io/linsa.git
synced 2026-04-26 02:08:40 +02:00
fix: remove unnecessary rerender link list
This commit is contained in:
@@ -153,10 +153,8 @@ export const LinkForm: React.FC<LinkFormProps> = ({
|
|||||||
})
|
})
|
||||||
|
|
||||||
const topicName = form.watch("topic")
|
const topicName = form.watch("topic")
|
||||||
const findTopic = React.useMemo(
|
const findTopic =
|
||||||
() => me && Topic.findUnique({ topicName }, JAZZ_GLOBAL_GROUP_ID, me),
|
me && Topic.findUnique({ topicName }, JAZZ_GLOBAL_GROUP_ID, me)
|
||||||
[topicName, me],
|
|
||||||
)
|
|
||||||
|
|
||||||
const selectedTopic = useCoState(Topic, findTopic, {})
|
const selectedTopic = useCoState(Topic, findTopic, {})
|
||||||
|
|
||||||
|
|||||||
@@ -67,32 +67,20 @@ const LinkList: React.FC<LinkListProps> = () => {
|
|||||||
|
|
||||||
const { deleteLink } = useLinkActions()
|
const { deleteLink } = useLinkActions()
|
||||||
const confirm = useConfirm()
|
const confirm = useConfirm()
|
||||||
const { me } = useAccount({ root: { personalLinks: [] } })
|
const { me } = useAccount({ root: { personalLinks: [{}] } })
|
||||||
|
|
||||||
const personalLinks = React.useMemo(
|
const personalLinks = me?.root.personalLinks || []
|
||||||
() => me?.root?.personalLinks || [],
|
const filteredLinks = personalLinks.filter((link) => {
|
||||||
[me?.root?.personalLinks],
|
if (state === "all") return true
|
||||||
)
|
if (!link?.learningState) return false
|
||||||
|
return link.learningState === state
|
||||||
const filteredLinks = React.useMemo(
|
})
|
||||||
() =>
|
const sortedLinks =
|
||||||
personalLinks.filter((link) => {
|
sort === "title"
|
||||||
if (state === "all") return true
|
? [...filteredLinks].sort((a, b) =>
|
||||||
if (!link?.learningState) return false
|
(a?.title || "").localeCompare(b?.title || ""),
|
||||||
return link.learningState === state
|
)
|
||||||
}),
|
: filteredLinks
|
||||||
[personalLinks, state],
|
|
||||||
)
|
|
||||||
|
|
||||||
const sortedLinks = React.useMemo(
|
|
||||||
() =>
|
|
||||||
sort === "title"
|
|
||||||
? [...filteredLinks].sort((a, b) =>
|
|
||||||
(a?.title || "").localeCompare(b?.title || ""),
|
|
||||||
)
|
|
||||||
: filteredLinks,
|
|
||||||
[filteredLinks, sort],
|
|
||||||
)
|
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (editId) {
|
if (editId) {
|
||||||
@@ -208,7 +196,7 @@ const LinkList: React.FC<LinkListProps> = () => {
|
|||||||
const handleDragEnd = (event: DragEndEvent) => {
|
const handleDragEnd = (event: DragEndEvent) => {
|
||||||
const { active, over } = event
|
const { active, over } = event
|
||||||
|
|
||||||
if (!active || !over || !me?.root?.personalLinks) {
|
if (!active || !over || !me?.root.personalLinks) {
|
||||||
console.error("Drag operation fail", { active, over })
|
console.error("Drag operation fail", { active, over })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user