diff --git a/shared/sources.ts b/shared/sources.ts index c93cbc8..d32627a 100644 --- a/shared/sources.ts +++ b/shared/sources.ts @@ -20,6 +20,7 @@ export const originSources = { "zhihu": { name: "知乎", type: "hottest", + color: "blue", home: "https://www.zhihu.com", }, "weibo": { @@ -47,12 +48,14 @@ export const originSources = { name: "华尔街见闻", interval: Time.Fast, type: "realtime", + color: "blue", home: "https://wallstreetcn.com/", title: "快讯", }, "36kr": { name: "36氪", type: "realtime", + color: "blue", home: "https://36kr.com", sub: { quick: { diff --git a/src/components/column/card.tsx b/src/components/column/card.tsx index 248d21b..40c3a19 100644 --- a/src/components/column/card.tsx +++ b/src/components/column/card.tsx @@ -59,8 +59,8 @@ export const CardWrapper = forwardRef(({ id, isDragg export function CardOverlay({ id }: { id: SourceID }) { return (
diff --git a/src/components/column/dnd.tsx b/src/components/column/dnd.tsx index a4eb9b4..4907377 100644 --- a/src/components/column/dnd.tsx +++ b/src/components/column/dnd.tsx @@ -1,19 +1,22 @@ +import type { PropsWithChildren } from "react" import { useCallback, useState } from "react" import type { DragEndEvent, DragStartEvent } from "@dnd-kit/core" import { DndContext, DragOverlay, + MeasuringStrategy, MouseSensor, TouchSensor, closestCenter, useSensor, useSensors, } from "@dnd-kit/core" -import { SortableContext, arrayMove, rectSortingStrategy, useSortable } from "@dnd-kit/sortable" +import type { AnimateLayoutChanges } from "@dnd-kit/sortable" +import { SortableContext, arrayMove, defaultAnimateLayoutChanges, rectSortingStrategy, useSortable } from "@dnd-kit/sortable" import { useAtom } from "jotai" import type { SourceID } from "@shared/types" import { CSS } from "@dnd-kit/utilities" -import { LayoutGroup, motion } from "framer-motion" +import { motion } from "framer-motion" import type { ItemsProps } from "./card" import { CardOverlay, CardWrapper } from "./card" import { currentSourcesAtom } from "~/atoms" @@ -22,42 +25,37 @@ export function Dnd() { const [items, setItems] = useAtom(currentSourcesAtom) return ( - {activeid => ( - - - {items.map(id => ( - - - - ))} - - - )} + }, + }} + > + {items.map(id => ( + + + + ))} + ) } @@ -65,10 +63,15 @@ export function Dnd() { interface DndProps { items: SourceID[] setItems: (update: SourceID[]) => void - children: (activeId: string | null) => React.ReactNode } -export function DndWrapper({ items, setItems, children }: DndProps) { +const measuringConfig = { + droppable: { + strategy: MeasuringStrategy.Always, + }, +} + +export function DndWrapper({ items, setItems, children }: PropsWithChildren) { const [activeId, setActiveId] = useState(null) const sensors = useSensors(useSensor(MouseSensor), useSensor(TouchSensor)) @@ -94,21 +97,37 @@ export function DndWrapper({ items, setItems, children }: DndProps) { return ( - {children(activeId)} + {children} - - {!!activeId && } + + {/* {!!activeId && } */} + ) } +const animateLayoutChanges: AnimateLayoutChanges = (args) => { + const { isSorting, wasDragging } = args + if (isSorting || wasDragging) { + return defaultAnimateLayoutChanges(args) + } + return true +} + function SortableCardWrapper({ id, ...props }: ItemsProps) { const { isDragging, @@ -117,7 +136,14 @@ function SortableCardWrapper({ id, ...props }: ItemsProps) { setNodeRef, transform, transition, - } = useSortable({ id }) + } = useSortable({ + id, + animateLayoutChanges, + transition: { + duration: 300, + easing: "cubic-bezier(0.25, 1, 0.5, 1)", + }, + }) const style = { transform: CSS.Transform.toString(transform),