Skip to content

Commit f4e3e92

Browse files
committed
fix: lock system tab ordering
1 parent caad61e commit f4e3e92

8 files changed

Lines changed: 35 additions & 17 deletions

File tree

scripts/source.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ function getUpdatedSourceIds() {
9696
try {
9797
const baseRef = getVersionBaseRef()
9898
const ids = new Map<string, number>()
99-
if (!baseRef) return []
99+
if (!baseRef) return
100100

101101
const changedFiles = git(["diff", "--name-only", baseRef, "--", "server/sources"])
102102
.split("\n")
@@ -115,7 +115,6 @@ function getUpdatedSourceIds() {
115115
.map(([id]) => id)
116116
} catch {
117117
consola.warn("Skip updated sources: failed to read git info.")
118-
return []
119118
}
120119
}
121120

@@ -140,9 +139,13 @@ try {
140139
}
141140

142141
try {
143-
const updatedSourceIds = JSON.stringify(getUpdatedSourceIds(), undefined, 2)
144-
writeFileSync(join(projectDir, "./shared/updated-sources.ts"), `export const updatedSourceIds = ${updatedSourceIds} as const\n`)
145-
consola.info("Generated updated-sources.ts")
142+
const updatedSourceIds = getUpdatedSourceIds()
143+
if (updatedSourceIds) {
144+
writeFileSync(join(projectDir, "./shared/updated-sources.ts"), `export const updatedSourceIds = ${JSON.stringify(updatedSourceIds, undefined, 2)} as const\n`)
145+
consola.info("Generated updated-sources.ts")
146+
} else {
147+
consola.info("Skipped updated-sources.ts")
148+
}
146149
} catch {
147150
consola.error("Failed to generate updated-sources.ts")
148151
}

shared/metadata.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ const updatedSourceIds = [..._updatedSourceIds] as SourceID[]
3838
export const fixedColumnIds = ["focus", "hottest", "realtime", "updated"] as const satisfies Partial<ColumnID>[]
3939
export const hiddenColumns = Object.keys(columns).filter(id => !fixedColumnIds.includes(id as any)) as HiddenColumnID[]
4040

41+
function getSortedSourceIds(type: "hottest" | "realtime") {
42+
return typeSafeObjectEntries(sources)
43+
.filter(([, v]) => v.type === type && !v.redirect)
44+
.map(([k]) => k)
45+
.sort((m, n) => m.localeCompare(n))
46+
}
47+
4148
export const metadata: Metadata = typeSafeObjectFromEntries(typeSafeObjectEntries(columns).map(([k, v]) => {
4249
switch (k) {
4350
case "focus":
@@ -48,12 +55,12 @@ export const metadata: Metadata = typeSafeObjectFromEntries(typeSafeObjectEntrie
4855
case "hottest":
4956
return [k, {
5057
name: v.zh,
51-
sources: typeSafeObjectEntries(sources).filter(([, v]) => v.type === "hottest" && !v.redirect).map(([k]) => k),
58+
sources: getSortedSourceIds("hottest"),
5259
}]
5360
case "realtime":
5461
return [k, {
5562
name: v.zh,
56-
sources: typeSafeObjectEntries(sources).filter(([, v]) => v.type === "realtime" && !v.redirect).map(([k]) => k),
63+
sources: getSortedSourceIds("realtime"),
5764
}]
5865
case "updated":
5966
return [k, {

shared/pre-sources.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ export const originSources = {
9797
color: "blue",
9898
home: "https://36kr.com",
9999
column: "tech",
100+
disable: "cf",
100101
sub: {
101102
quick: {
102103
title: "快讯",

shared/sources.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
"redirect": "36kr-quick",
109109
"name": "36氪",
110110
"type": "realtime",
111+
"disable": "cf",
111112
"column": "tech",
112113
"home": "https://36kr.com",
113114
"color": "blue",
@@ -117,6 +118,7 @@
117118
"36kr-quick": {
118119
"name": "36氪",
119120
"type": "realtime",
121+
"disable": "cf",
120122
"column": "tech",
121123
"home": "https://36kr.com",
122124
"color": "blue",
@@ -126,6 +128,7 @@
126128
"36kr-renqi": {
127129
"name": "36氪",
128130
"type": "hottest",
131+
"disable": "cf",
129132
"column": "tech",
130133
"home": "https://36kr.com",
131134
"color": "blue",

shared/updated-sources.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ export const updatedSourceIds = [
2020
"bilibili-hot-video",
2121
"bilibili-ranking",
2222
"kuaishou",
23-
"toutiao",
23+
"toutiao"
2424
] as const

src/atoms/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export const currentSourcesAtom = atom((get) => {
2121
const id = get(currentColumnIDAtom)
2222
return get(primitiveMetadataAtom).data[id]
2323
}, (get, set, update: Update<SourceID[]>) => {
24+
if (get(currentColumnIDAtom) !== "focus") return
2425
const _ = update instanceof Function ? update(get(currentSourcesAtom)) : update
2526
set(primitiveMetadataAtom, {
2627
updatedTime: Date.now(),

src/atoms/primitiveMetadataAtom.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ export function preprocessMetadata(target: PrimitiveMetadata) {
4444
.filter(([id]) => initialMetadata[id])
4545
.map(([id, s]) => {
4646
if (id === "focus") return [id, s.filter(k => sources[k]).map(k => sources[k].redirect ?? k)]
47-
const oldS = s.filter(k => initialMetadata[id].includes(k)).map(k => sources[k].redirect ?? k)
48-
const newS = initialMetadata[id].filter(k => !oldS.includes(k))
49-
return [id, [...oldS, ...newS]]
47+
return [id, initialMetadata[id]]
5048
}),
5149
),
5250
},

src/components/column/dnd.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ import { useSortable } from "../common/dnd/useSortable"
1414
import { OverlayScrollbar } from "../common/overlay-scrollbar"
1515
import type { ItemsProps } from "./card"
1616
import { CardWrapper } from "./card"
17-
import { currentSourcesAtom } from "~/atoms"
17+
import { currentColumnIDAtom, currentSourcesAtom } from "~/atoms"
1818

1919
const AnimationDuration = 200
2020
const WIDTH = 350
2121
export function Dnd() {
2222
const [items, setItems] = useAtom(currentSourcesAtom)
23+
const currentColumnID = useAtomValue(currentColumnIDAtom)
24+
const sortable = currentColumnID === "focus"
2325
const [parent] = useAutoAnimate({ duration: AnimationDuration })
2426
useEntireQuery(items)
2527
const { width } = useWindowSize()
@@ -31,7 +33,7 @@ export function Dnd() {
3133
if (!items.length) return null
3234

3335
return (
34-
<DndWrapper items={items} setItems={setItems} isSingleColumn={isMobile}>
36+
<DndWrapper items={items} setItems={setItems} isSingleColumn={isMobile} sortable={sortable}>
3537
<OverlayScrollbar defer className="overflow-x-auto">
3638
<motion.ol
3739
className={isMobile
@@ -80,7 +82,7 @@ export function Dnd() {
8082
},
8183
}}
8284
>
83-
<SortableCardWrapper id={id} />
85+
<SortableCardWrapper id={id} sortable={sortable} />
8486
</motion.li>
8587
))}
8688
</motion.ol>
@@ -94,10 +96,11 @@ export function Dnd() {
9496
)
9597
}
9698

97-
function DndWrapper({ items, setItems, isSingleColumn, children }: PropsWithChildren<{
99+
function DndWrapper({ items, setItems, isSingleColumn, sortable, children }: PropsWithChildren<{
98100
items: SourceID[]
99101
setItems: (items: SourceID[]) => void
100102
isSingleColumn: boolean
103+
sortable: boolean
101104
}>) {
102105
const onDropTargetChange = useCallback(({ location, source }: BaseEventPayload<ElementDragType>) => {
103106
const traget = location.current.dropTargets[0]
@@ -122,6 +125,8 @@ function DndWrapper({ items, setItems, isSingleColumn, children }: PropsWithChil
122125
wait: AnimationDuration,
123126
})
124127
const { el } = useAtomValue(goToTopAtom)
128+
if (!sortable) return children
129+
125130
return (
126131
<DndContext onDropTargetChange={run} autoscroll={el ? { element: el } : undefined}>
127132
{children}
@@ -166,7 +171,7 @@ function CardOverlay({ id }: { id: SourceID }) {
166171
)
167172
}
168173

169-
function SortableCardWrapper({ id }: ItemsProps) {
174+
function SortableCardWrapper({ id, sortable }: ItemsProps & { sortable: boolean }) {
170175
const {
171176
isDragging,
172177
setNodeRef,
@@ -186,7 +191,7 @@ function SortableCardWrapper({ id }: ItemsProps) {
186191
ref={setNodeRef}
187192
id={id}
188193
isDragging={isDragging}
189-
setHandleRef={setHandleRef}
194+
setHandleRef={sortable ? setHandleRef : undefined}
190195
/>
191196
{OverlayContainer && createPortal(<CardOverlay id={id} />, OverlayContainer)}
192197
</>

0 commit comments

Comments
 (0)