mirror of
https://github.com/linsa-io/linsa.git
synced 2026-04-24 17:28:41 +02:00
fix: link (#115)
* start * . * seeding connections * . * wip * wip: learning state * wip: notes section * wip: many * topics * chore: update schema * update package * update sidebar * update page section * feat: profile * fix: remove z index * fix: wrong type * add avatar * add avatar * wip * . * store page section key * remove atom page section * fix rerender * fix rerender * fix rerender * fix rerender * fix link * search light/dark mode * bubble menu ui * . * fix: remove unecessary code * chore: mark as old for old schema * chore: adapt new schema * fix: add topic schema but null for now * fix: add icon on personal link * fix: list item * fix: set url fetched when editing * fix: remove image * feat: add icon to link * feat: custom url zod validation * fix: metadata test * chore: update utils * fix: link * fix: url fetcher * . * . * fix: add link, section * chore: seeder * . * . * . * . * fix: change checkbox to learning state * fix: click outside editing form * feat: constant * chore: move to master folder * chore: adapt new schema * chore: cli for new schema * fix: new schema for dev seed * fix: seeding * update package * chore: forcegraph seed * bottombar * if isEdit delete icon * showCreate X button * . * options * chore: implement topic from public global group * chore: update learning state * fix: change implementation for outside click * chore: implement new form param * chore: update env example * feat: link form refs exception * new page button layout, link topic search fixed * chore: enable topic * chore: update seed * profile * chore: move framer motion package from root to web and add nuqs * chore: add LearningStateValue * chore: implement active state * profile * chore: use fancy switch and update const * feat: filter implementation * dropdown menu * . * sidebar topics * topic selected color * feat: topic detail * fix: collapsible page * pages - sorted by, layout, visible mode * . * . * . * topic status sidebar * topic button and count * fix: topic * page delete/topic buttons * search ui * selected topic for page * selected topic status sidebar * removed footer * update package * . --------- Co-authored-by: Nikita <github@nikiv.dev> Co-authored-by: marshennikovaolga <marshennikova@gmail.com> Co-authored-by: Kisuyo <ig.intr3st@gmail.com>
This commit is contained in:
@@ -1,34 +1,68 @@
|
||||
import { co, CoList, CoMap } from "jazz-tools"
|
||||
import { nullable } from "../types"
|
||||
import { GlobalLink } from "./global-link"
|
||||
import { GlobalTopic } from "./global-topic"
|
||||
import { co, CoList, CoMap, Encoders, ID } from "jazz-tools"
|
||||
import { Topic } from "./master/topic"
|
||||
|
||||
export class LinkMetadata extends CoMap {
|
||||
url = co.string
|
||||
title = co.string
|
||||
favicon = co.string
|
||||
description = nullable(co.string)
|
||||
class BaseModel extends CoMap {
|
||||
createdAt = co.encoded(Encoders.Date)
|
||||
updatedAt = co.encoded(Encoders.Date)
|
||||
}
|
||||
|
||||
/*
|
||||
* Link is link user added, it wraps over Link and lets user add notes and other things to it,
|
||||
* (as well as set own title/description/summary if GlobalLink ones is not good enough or is lacking)
|
||||
*/
|
||||
export class PersonalLink extends CoMap {
|
||||
export class PersonalLink extends BaseModel {
|
||||
url = co.string
|
||||
icon = co.optional.string // is an icon URL
|
||||
title = co.string
|
||||
slug = co.string
|
||||
description = co.optional.string
|
||||
completed = co.boolean
|
||||
sequence = co.number
|
||||
isLink = co.boolean
|
||||
meta = co.optional.ref(LinkMetadata)
|
||||
|
||||
// not yet implemented
|
||||
learningState = co.optional.literal("wantToLearn", "learning", "learned")
|
||||
notes = co.optional.string
|
||||
summary = co.optional.string
|
||||
globalLink = co.optional.ref(GlobalLink)
|
||||
topic = co.optional.ref(GlobalTopic)
|
||||
topic = co.optional.ref(Topic)
|
||||
}
|
||||
|
||||
export class PersonalLinkLists extends CoList.Of(co.ref(PersonalLink)) {}
|
||||
|
||||
export function updatePersonalLink(link: PersonalLink, data: Partial<PersonalLink>): void {
|
||||
Object.assign(link, { ...data, updatedAt: new Date() })
|
||||
}
|
||||
|
||||
export function createPersonalLinkList(owner: { group: any }): PersonalLinkLists {
|
||||
return PersonalLinkLists.create([], { owner: owner.group })
|
||||
}
|
||||
|
||||
export function addToPersonalLinkList(list: PersonalLinkLists, item: PersonalLink): void {
|
||||
list.push(item)
|
||||
}
|
||||
|
||||
export function removeFromPersonalLinkList(list: PersonalLinkLists, id: ID<PersonalLink>): void {
|
||||
const index = list.findIndex(item => item?.id === id)
|
||||
if (index !== -1) {
|
||||
list.splice(index, 1)
|
||||
}
|
||||
}
|
||||
|
||||
export function updateInPersonalLinkList(
|
||||
list: PersonalLinkLists,
|
||||
id: ID<PersonalLink>,
|
||||
data: Partial<PersonalLink>
|
||||
): void {
|
||||
const item = list.find(item => item?.id === id)
|
||||
if (item) {
|
||||
Object.assign(item, { ...data, updatedAt: new Date() })
|
||||
}
|
||||
}
|
||||
|
||||
export function getFromPersonalLinkList(
|
||||
list: PersonalLinkLists,
|
||||
id: ID<PersonalLink>
|
||||
): PersonalLink | null | undefined {
|
||||
return list.find(item => item?.id === id)
|
||||
}
|
||||
|
||||
export function safelyAccessPersonalLink<T>(
|
||||
link: PersonalLink | null | undefined,
|
||||
accessor: (link: PersonalLink) => T,
|
||||
defaultValue: T
|
||||
): T {
|
||||
return link ? accessor(link) : defaultValue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user