mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-14 08:34:25 +03:00
messages: fix last updated sorting
This commit is contained in:
parent
f2f0cac31e
commit
867037804d
@ -1,8 +1,9 @@
|
||||
import { useEffect, useState, useCallback, useMemo } from 'react';
|
||||
import _ from 'lodash';
|
||||
import { patp2dec } from 'urbit-ob';
|
||||
import f, { compose, memoize } from 'lodash/fp';
|
||||
import bigInt, { BigInteger } from 'big-integer';
|
||||
import { Association, Contact } from '@urbit/api';
|
||||
import { Association, Contact, Patp } from '@urbit/api';
|
||||
import useLocalState from '../state/local';
|
||||
import produce, { enableMapSet } from 'immer';
|
||||
import useSettingsState from '../state/settings';
|
||||
@ -369,11 +370,15 @@ export function numToUd(num: number) {
|
||||
f.reverse,
|
||||
f.chunk(3),
|
||||
f.reverse,
|
||||
f.map(s => s.join('')),
|
||||
f.map(f.flow(f.reverse, f.join(''))),
|
||||
f.join('.')
|
||||
)(num.toString());
|
||||
}
|
||||
|
||||
export function patpToUd(patp: Patp) {
|
||||
return numToUd(patp2dec(patp))
|
||||
}
|
||||
|
||||
export function usePreventWindowUnload(shouldPreventDefault: boolean, message = 'You have unsaved changes. Are you sure you want to exit?') {
|
||||
useEffect(() => {
|
||||
if (!shouldPreventDefault)
|
||||
|
@ -152,7 +152,7 @@ export function useGraphForAssoc(association: Association) {
|
||||
window.useGraphState = useGraphState;
|
||||
|
||||
export function useInbox() {
|
||||
return useGraphState(s => s.graphs[`${window.ship}/inbox`]);
|
||||
return useGraphState(s => s.graphs[`${window.ship}/inbox`] || new BigIntOrderedMap());
|
||||
}
|
||||
|
||||
export function useDM(ship: string) {
|
||||
|
@ -9,6 +9,7 @@ import useGraphState, { useDM } from '~/logic/state/graph';
|
||||
import useHarkState, { useHarkDm } from '~/logic/state/hark';
|
||||
import useSettingsState, { selectCalmState } from '~/logic/state/settings';
|
||||
import { ChatPane } from './components/ChatPane';
|
||||
import {patpToUd} from '~/logic/lib/util';
|
||||
|
||||
interface DmResourceProps {
|
||||
ship: string;
|
||||
@ -36,7 +37,7 @@ export function DmResource(props: DmResourceProps) {
|
||||
const nickname = showNickname ? contact!.nickname : cite(ship) ?? ship;
|
||||
|
||||
useEffect(() => {
|
||||
api.graph.getNewest(`~${window.ship}`, 'inbox', 100, `/${patp2dec(ship)}`);
|
||||
api.graph.getNewest(`~${window.ship}`, 'inbox', 100, `/${patpToUd(ship)}`);
|
||||
}, [ship]);
|
||||
|
||||
const fetchMessages = useCallback(
|
||||
|
@ -1,6 +1,6 @@
|
||||
import React, { ReactElement } from 'react';
|
||||
import { Associations, AppAssociations, Groups, Rolodex, Graph } from '@urbit/api';
|
||||
import { patp } from 'urbit-ob';
|
||||
import { Associations, AppAssociations, Groups, Rolodex, Graph, UnreadStats } from '@urbit/api';
|
||||
import { patp, patp2dec } from 'urbit-ob';
|
||||
|
||||
import { alphabeticalOrder } from '~/logic/lib/util';
|
||||
import { SidebarAppConfigs, SidebarListConfig, SidebarSort } from './types';
|
||||
@ -8,10 +8,12 @@ import { SidebarAssociationItem, SidebarDmItem } from './SidebarItem';
|
||||
import { Workspace } from '~/types/workspace';
|
||||
import useMetadataState from '~/logic/state/metadata';
|
||||
import {useInbox} from '~/logic/state/graph';
|
||||
import useHarkState from '~/logic/state/hark';
|
||||
|
||||
function sidebarSort(
|
||||
associations: AppAssociations,
|
||||
apps: SidebarAppConfigs
|
||||
apps: SidebarAppConfigs,
|
||||
inboxUnreads: Record<string, UnreadStats>
|
||||
): Record<SidebarSort, (a: string, b: string) => number> {
|
||||
const alphabetical = (a: string, b: string) => {
|
||||
const aAssoc = associations[a];
|
||||
@ -28,8 +30,12 @@ function sidebarSort(
|
||||
const aAppName = aAssoc?.['app-name'];
|
||||
const bAppName = bAssoc?.['app-name'];
|
||||
|
||||
const aUpdated = apps[aAppName]?.lastUpdated(a) || 0;
|
||||
const bUpdated = apps[bAppName]?.lastUpdated(b) || 0;
|
||||
const aUpdated = a.startsWith('~')
|
||||
? (inboxUnreads?.[`/${patp2dec(a)}`]?.last)
|
||||
: apps[aAppName]?.lastUpdated(a) || 0;
|
||||
const bUpdated = b.startsWith('~')
|
||||
? (inboxUnreads?.[`/${patp2dec(b)}`]?.last || 0)
|
||||
: apps[bAppName]?.lastUpdated(b) || 0;
|
||||
|
||||
return bUpdated - aUpdated || alphabetical(a, b);
|
||||
};
|
||||
@ -80,10 +86,11 @@ export function SidebarList(props: {
|
||||
const { selected, group, config, workspace } = props;
|
||||
const associations = useMetadataState(state => state.associations);
|
||||
const inbox = useInbox();
|
||||
const unreads = useHarkState(s => s.unreads.graph?.[`/ship/~${window.ship}/inbox`]);
|
||||
|
||||
|
||||
const ordered = getItems(associations, workspace, inbox);
|
||||
//.sort(sidebarSort(associations, props.apps)[config.sortBy]);
|
||||
const ordered = getItems(associations, workspace, inbox)
|
||||
.sort(sidebarSort(associations, props.apps, unreads)[config.sortBy]);
|
||||
|
||||
return (
|
||||
<>
|
||||
|
Loading…
Reference in New Issue
Block a user