diff --git a/src/components/generic/Table/index.tsx b/src/components/generic/Table/index.tsx index 124dd661..29b0679b 100755 --- a/src/components/generic/Table/index.tsx +++ b/src/components/generic/Table/index.tsx @@ -1,10 +1,19 @@ import { ChevronDownIcon, ChevronUpIcon } from "lucide-react"; import { useState } from "react"; import React from "react"; +import { cn } from "@core/utils/cn.ts"; + +interface FavoriteIconProps { + showFavorite: boolean; +} + +interface WrapperProps { + children: React.ReactElement; +} export interface TableProps { headings: Heading[]; - rows: React.ReactNode[][]; + rows: React.ReactElement[][]; } export interface Heading { @@ -61,6 +70,13 @@ export const Table = ({ headings, rows }: TableProps) => { const elementA = getElement(a[columnIndex]); const elementB = getElement(b[columnIndex]); + // Avatar contains the prop showFavorite which indicates isFavorite + const favA = a[0]?.props?.children?.props?.showFavorite ?? false; + const favB = b[0]?.props?.children?.props?.showFavorite ?? false; + + // Always put favorites at the top + if (favA !== favB) return favA ? -1 : 1; + if (sortColumn === "Last Heard") { const aTimestamp = elementA?.props?.children?.props?.timestamp ?? 0; const bTimestamp = elementB?.props?.children?.props?.timestamp ?? 0; @@ -142,13 +158,17 @@ export const Table = ({ headings, rows }: TableProps) => { : null; const rowKey = firstCellKey ?? Math.random().toString(); // Use random only as last resort + const isFavorite = row[0]?.props?.children?.props?.showFavorite ?? + false; return ( {row.map((item, cellIndex) => { const cellKey = `${rowKey}_${cellIndex}`; diff --git a/src/pages/Messages.tsx b/src/pages/Messages.tsx index e8146d3f..457b4c83 100644 --- a/src/pages/Messages.tsx +++ b/src/pages/Messages.tsx @@ -60,7 +60,11 @@ export const MessagesPage = () => { ...node, unreadCount: unreadCounts.get(node.num) ?? 0, })) - .sort((a, b) => b.unreadCount - a.unreadCount); + .sort((a, b) => { + const diff = b.unreadCount - a.unreadCount; + if (diff !== 0) return diff; + return Number(b.isFavorite) - Number(a.isFavorite); + }); }; const allChannels = Array.from(channels.values()); diff --git a/src/pages/Nodes.tsx b/src/pages/Nodes.tsx index f3102ed8..8165ed60 100644 --- a/src/pages/Nodes.tsx +++ b/src/pages/Nodes.tsx @@ -35,7 +35,7 @@ const NodesPage = (): JSX.Element => { Types.PacketMetadata | undefined >(); const [selectedLocation, setSelectedLocation] = useState< - Types.PacketMetadata | undefined + Types.PacketMetadata | undefined >(); const [searchTerm, setSearchTerm] = useState(""); const deferredSearch = useDeferredValue(searchTerm); @@ -85,7 +85,6 @@ const NodesPage = (): JSX.Element => { } - className="flex flex-col w-full" >