mirror of
https://github.com/linsa-io/linsa.git
synced 2026-01-12 12:20:23 +01:00
* feat: keyboard nav * fix: link update * feat: reusable learning state * chore: use new learning state * feat: add to my profile * . * . * feat: on enter open the link * fix: lint * fix: use eslint v8 instead of v9 * fix: add to my profile * chore: update personal link schema * chore: update personal page schema * fix: update detail wrapper * fix: update page section * removing option for learning status * removing option for learning status for topic * feat: add createdAt and updatedAt for personal Page * chore: update page section component * chore: remove chevron from sub menu * fix: sidebar * chore: add focus and disable toast * feat: la editor add execption for no command class * fix: la editor style and fix page detail * fix: title * fix: topic learning state * chore: add showSearch for learning state * fix: bunch stuff * chore: link list and item handle learning state * chore: set expand to false * feat: personal link for topic detail * chore: hook use topic data * chore: go to list * fix: link and topic * feat(utils): new keyboard utils * feat(store): add linkOpenPopoverForIdAtom for link * chore: using memo for use topic data * fix: remove duplicate component * chore: performance for topic detail lint item * refactor: remove LinkOptions component * chore: improve performance for list * feat: added LinkRoute copmonent * chore: link manage * feat: bottom bar * fix: link * fix: page wrapper * fix: import thing * chore: added a displayname * refactor: page detail * refactor: page detail * fix: add topic to personal link form link * fix: only show page count if more than zero * fix: sidebar topic section --------- Co-authored-by: Nikita <github@nikiv.dev> Co-authored-by: marshennikovaolga <marshennikova@gmail.com>
100 lines
2.6 KiB
TypeScript
100 lines
2.6 KiB
TypeScript
"use client"
|
|
|
|
import * as React from "react"
|
|
import { ContentHeader, SidebarToggleButton } from "@/components/custom/content-header"
|
|
import { ListOfTopics, Topic } from "@/lib/schema"
|
|
import { LearningStateSelector } from "@/components/custom/learning-state-selector"
|
|
import { useAccount } from "@/lib/providers/jazz-provider"
|
|
import { LearningStateValue } from "@/lib/constants"
|
|
|
|
interface TopicDetailHeaderProps {
|
|
topic: Topic
|
|
}
|
|
|
|
export const TopicDetailHeader = React.memo(function TopicDetailHeader({ topic }: TopicDetailHeaderProps) {
|
|
const { me } = useAccount({
|
|
root: {
|
|
topicsWantToLearn: [],
|
|
topicsLearning: [],
|
|
topicsLearned: []
|
|
}
|
|
})
|
|
|
|
let p: {
|
|
index: number
|
|
topic?: Topic | null
|
|
learningState: LearningStateValue
|
|
} | null = null
|
|
|
|
const wantToLearnIndex = me?.root.topicsWantToLearn.findIndex(t => t?.id === topic.id) ?? -1
|
|
if (wantToLearnIndex !== -1) {
|
|
p = {
|
|
index: wantToLearnIndex,
|
|
topic: me?.root.topicsWantToLearn[wantToLearnIndex],
|
|
learningState: "wantToLearn"
|
|
}
|
|
}
|
|
|
|
const learningIndex = me?.root.topicsLearning.findIndex(t => t?.id === topic.id) ?? -1
|
|
if (learningIndex !== -1) {
|
|
p = {
|
|
index: learningIndex,
|
|
topic: me?.root.topicsLearning[learningIndex],
|
|
learningState: "learning"
|
|
}
|
|
}
|
|
|
|
const learnedIndex = me?.root.topicsLearned.findIndex(t => t?.id === topic.id) ?? -1
|
|
if (learnedIndex !== -1) {
|
|
p = {
|
|
index: learnedIndex,
|
|
topic: me?.root.topicsLearned[learnedIndex],
|
|
learningState: "learned"
|
|
}
|
|
}
|
|
|
|
const handleAddToProfile = (learningState: LearningStateValue) => {
|
|
const topicLists: Record<LearningStateValue, (ListOfTopics | null) | undefined> = {
|
|
wantToLearn: me?.root.topicsWantToLearn,
|
|
learning: me?.root.topicsLearning,
|
|
learned: me?.root.topicsLearned
|
|
}
|
|
|
|
const removeFromList = (state: LearningStateValue, index: number) => {
|
|
topicLists[state]?.splice(index, 1)
|
|
}
|
|
|
|
if (p) {
|
|
if (learningState === p.learningState) {
|
|
removeFromList(p.learningState, p.index)
|
|
return
|
|
}
|
|
removeFromList(p.learningState, p.index)
|
|
}
|
|
|
|
topicLists[learningState]?.push(topic)
|
|
}
|
|
|
|
return (
|
|
<ContentHeader className="px-6 py-5 max-lg:px-4">
|
|
<div className="flex min-w-0 shrink-0 items-center gap-1.5">
|
|
<SidebarToggleButton />
|
|
<div className="flex min-h-0 items-center">
|
|
<span className="truncate text-left text-xl font-bold">{topic.prettyName}</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="flex flex-auto"></div>
|
|
|
|
<LearningStateSelector
|
|
showSearch={false}
|
|
value={p?.learningState || ""}
|
|
onChange={handleAddToProfile}
|
|
defaultLabel="Add to my profile"
|
|
/>
|
|
</ContentHeader>
|
|
)
|
|
})
|
|
|
|
TopicDetailHeader.displayName = "TopicDetailHeader"
|