Skip to content

Commit

Permalink
mobile: fix list not updating on change date sort
Browse files Browse the repository at this point in the history
  • Loading branch information
ammarahm-ed committed Sep 4, 2023
1 parent 003b3d2 commit a0f25c4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
14 changes: 8 additions & 6 deletions apps/mobile/app/components/list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,10 @@ const renderItems = {
const RenderItem = ({ item, index, type, ...restArgs }) => {
if (!item) return <View />;
const Item = renderItems[item.itemType || item.type] || View;
const groupOptions = db.settings?.getGroupOptions(type);
const dateBy =
groupOptions.sortBy !== "title" ? groupOptions.sortBy : "dateEdited";
const totalNotes = getTotalNotes(item);

return (
<Item
item={item}
dateBy={dateBy}
index={index}
type={type}
totalNotes={totalNotes}
Expand Down Expand Up @@ -103,6 +98,12 @@ const List = ({
(type === "notes" && notesListMode === "compact") ||
type === "notebooks" ||
notebooksListMode === "compact";
const groupType =
screen === "Notes" ? "home" : screen === "Favorites" ? "favorites" : type;

const groupOptions = db.settings?.getGroupOptions(groupType);
const dateBy =
groupOptions.sortBy !== "title" ? groupOptions.sortBy : "dateEdited";

const renderItem = React.useCallback(
({ item, index }) => (
Expand All @@ -111,6 +112,7 @@ const List = ({
index={index}
color={headerProps?.color}
title={headerProps?.heading}
dateBy={dateBy}
type={
screen === "Notes"
? "home"
Expand All @@ -122,7 +124,7 @@ const List = ({
isSheet={isSheet}
/>
),
[headerProps?.color, headerProps?.heading, screen, type, isSheet]
[headerProps?.color, headerProps?.heading, screen, type, isSheet, dateBy]
);

const _onRefresh = async () => {
Expand Down
4 changes: 4 additions & 0 deletions packages/common/src/hooks/use-time-ago.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ export function useTimeAgo(

useEffect(() => {
if (!live) return;
const value = getTimeAgo(datetime, locale);
onUpdate?.(value);
setTimeAgo(value);

const reset = setInterval(() => {
const value = getTimeAgo(datetime, locale);
onUpdate?.(value);
Expand Down

0 comments on commit a0f25c4

Please sign in to comment.