Skip to content
Snippets Groups Projects
Unverified Commit 672dd5ea authored by Joel Jeremy Marquez's avatar Joel Jeremy Marquez Committed by GitHub
Browse files

[Mobile] Fix account notes not retrieving correctly in mobile (#2599)

* Fix account notes not retrieving correctly

* Release notes

* Update release notes

* Fix type errors
parent b101f998
No related branches found
No related tags found
No related merge requests found
import React, { useEffect, useRef, useState, type ComponentProps } from 'react'; import React, { useEffect, useRef, useState, type ComponentProps } from 'react';
import { useLiveQuery } from 'loot-core/src/client/query-hooks';
import { send } from 'loot-core/src/platform/client/fetch'; import { send } from 'loot-core/src/platform/client/fetch';
import { q } from 'loot-core/src/shared/query';
import { type NoteEntity } from 'loot-core/types/models';
import { useNotes } from '../hooks/useNotes';
import { SvgCustomNotesPaper } from '../icons/v2'; import { SvgCustomNotesPaper } from '../icons/v2';
import { type CSSProperties, theme } from '../style'; import { type CSSProperties, theme } from '../style';
...@@ -32,11 +30,7 @@ export function NotesButton({ ...@@ -32,11 +30,7 @@ export function NotesButton({
}: NotesButtonProps) { }: NotesButtonProps) {
const triggerRef = useRef(null); const triggerRef = useRef(null);
const [isOpen, setIsOpen] = useState<boolean>(false); const [isOpen, setIsOpen] = useState<boolean>(false);
const data = useLiveQuery<NoteEntity[]>( const note = useNotes(id) || '';
() => q('notes').filter({ id }).select('*'),
[id],
);
const note = data && data.length > 0 ? data[0].note : '';
const hasNotes = note && note !== ''; const hasNotes = note && note !== '';
const [tempNotes, setTempNotes] = useState<string>(note); const [tempNotes, setTempNotes] = useState<string>(note);
......
import React, { type ComponentProps, useState } from 'react'; import React, { type ComponentProps, useState } from 'react';
import { useLiveQuery } from 'loot-core/src/client/query-hooks';
import { q } from 'loot-core/src/shared/query';
import { type AccountEntity } from 'loot-core/types/models'; import { type AccountEntity } from 'loot-core/types/models';
import { useAccounts } from '../../hooks/useAccounts'; import { useAccounts } from '../../hooks/useAccounts';
import { useNotes } from '../../hooks/useNotes';
import { SvgClose, SvgDotsHorizontalTriple, SvgLockOpen } from '../../icons/v1'; import { SvgClose, SvgDotsHorizontalTriple, SvgLockOpen } from '../../icons/v1';
import { SvgNotesPaper } from '../../icons/v2'; import { SvgNotesPaper } from '../../icons/v2';
import { type CSSProperties, styles, theme } from '../../style'; import { type CSSProperties, styles, theme } from '../../style';
...@@ -16,11 +15,6 @@ import { type CommonModalProps } from '../Modals'; ...@@ -16,11 +15,6 @@ import { type CommonModalProps } from '../Modals';
import { Notes } from '../Notes'; import { Notes } from '../Notes';
import { Tooltip } from '../tooltips'; import { Tooltip } from '../tooltips';
type NoteEntity = {
id: string;
note: string;
};
type AccountMenuModalProps = { type AccountMenuModalProps = {
modalProps: CommonModalProps; modalProps: CommonModalProps;
accountId: string; accountId: string;
...@@ -42,11 +36,7 @@ export function AccountMenuModal({ ...@@ -42,11 +36,7 @@ export function AccountMenuModal({
}: AccountMenuModalProps) { }: AccountMenuModalProps) {
const accounts = useAccounts(); const accounts = useAccounts();
const account = accounts.find(c => c.id === accountId); const account = accounts.find(c => c.id === accountId);
const data = useLiveQuery( const originalNotes = useNotes(`account-${accountId}`);
() => q('notes').filter({ id: account?.id }).select('*'),
[account?.id],
) as NoteEntity[] | null;
const originalNotes = data && data.length > 0 ? data[0].note : null;
const _onClose = () => { const _onClose = () => {
modalProps?.onClose(); modalProps?.onClose();
......
// @ts-strict-ignore // @ts-strict-ignore
import React, { type ComponentProps, useState } from 'react'; import React, { type ComponentProps, useState } from 'react';
import { useLiveQuery } from 'loot-core/src/client/query-hooks'; import { type CategoryGroupEntity } from 'loot-core/src/types/models';
import { q } from 'loot-core/src/shared/query';
import {
type CategoryGroupEntity,
type NoteEntity,
} from 'loot-core/src/types/models';
import { useCategories } from '../../hooks/useCategories'; import { useCategories } from '../../hooks/useCategories';
import { useNotes } from '../../hooks/useNotes';
import { SvgDotsHorizontalTriple, SvgAdd, SvgTrash } from '../../icons/v1'; import { SvgDotsHorizontalTriple, SvgAdd, SvgTrash } from '../../icons/v1';
import { SvgNotesPaper, SvgViewHide, SvgViewShow } from '../../icons/v2'; import { SvgNotesPaper, SvgViewHide, SvgViewShow } from '../../icons/v2';
import { type CSSProperties, styles, theme } from '../../style'; import { type CSSProperties, styles, theme } from '../../style';
...@@ -42,11 +38,7 @@ export function CategoryGroupMenuModal({ ...@@ -42,11 +38,7 @@ export function CategoryGroupMenuModal({
}: CategoryGroupMenuModalProps) { }: CategoryGroupMenuModalProps) {
const { grouped: categoryGroups } = useCategories(); const { grouped: categoryGroups } = useCategories();
const group = categoryGroups.find(g => g.id === groupId); const group = categoryGroups.find(g => g.id === groupId);
const data = useLiveQuery<NoteEntity[]>( const notes = useNotes(group.id);
() => q('notes').filter({ id: group.id }).select('*'),
[group.id],
);
const notes = data && data.length > 0 ? data[0].note : null;
const _onClose = () => { const _onClose = () => {
modalProps?.onClose(); modalProps?.onClose();
......
// @ts-strict-ignore // @ts-strict-ignore
import React, { useState } from 'react'; import React, { useState } from 'react';
import { useLiveQuery } from 'loot-core/src/client/query-hooks'; import { type CategoryEntity } from 'loot-core/src/types/models';
import { q } from 'loot-core/src/shared/query';
import {
type CategoryEntity,
type NoteEntity,
} from 'loot-core/src/types/models';
import { useCategory } from '../../hooks/useCategory'; import { useCategory } from '../../hooks/useCategory';
import { useCategoryGroup } from '../../hooks/useCategoryGroup'; import { useCategoryGroup } from '../../hooks/useCategoryGroup';
import { useNotes } from '../../hooks/useNotes';
import { SvgDotsHorizontalTriple, SvgTrash } from '../../icons/v1'; import { SvgDotsHorizontalTriple, SvgTrash } from '../../icons/v1';
import { SvgNotesPaper, SvgViewHide, SvgViewShow } from '../../icons/v2'; import { SvgNotesPaper, SvgViewHide, SvgViewShow } from '../../icons/v2';
import { type CSSProperties, styles, theme } from '../../style'; import { type CSSProperties, styles, theme } from '../../style';
...@@ -40,12 +36,7 @@ export function CategoryMenuModal({ ...@@ -40,12 +36,7 @@ export function CategoryMenuModal({
}: CategoryMenuModalProps) { }: CategoryMenuModalProps) {
const category = useCategory(categoryId); const category = useCategory(categoryId);
const categoryGroup = useCategoryGroup(category?.cat_group); const categoryGroup = useCategoryGroup(category?.cat_group);
const data = useLiveQuery<NoteEntity[]>( const originalNotes = useNotes(category.id);
() => q('notes').filter({ id: category.id }).select('*'),
[category.id],
);
const originalNotes = data && data.length > 0 ? data[0].note : null;
const _onClose = () => { const _onClose = () => {
modalProps?.onClose(); modalProps?.onClose();
onClose?.(); onClose?.();
......
// @ts-strict-ignore // @ts-strict-ignore
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { useLiveQuery } from 'loot-core/src/client/query-hooks'; import { useNotes } from '../../hooks/useNotes';
import { q } from 'loot-core/src/shared/query';
import { type NoteEntity } from 'loot-core/types/models';
import { SvgCheck } from '../../icons/v2'; import { SvgCheck } from '../../icons/v2';
import { Button } from '../common/Button'; import { Button } from '../common/Button';
import { Modal } from '../common/Modal'; import { Modal } from '../common/Modal';
...@@ -20,11 +17,7 @@ type NotesProps = { ...@@ -20,11 +17,7 @@ type NotesProps = {
}; };
export function Notes({ modalProps, id, name, onSave }: NotesProps) { export function Notes({ modalProps, id, name, onSave }: NotesProps) {
const data = useLiveQuery<NoteEntity[]>( const originalNotes = useNotes(id);
() => q('notes').filter({ id }).select('*'),
[id],
);
const originalNotes = data && data.length > 0 ? data[0].note : null;
const [notes, setNotes] = useState(originalNotes); const [notes, setNotes] = useState(originalNotes);
useEffect(() => setNotes(originalNotes), [originalNotes]); useEffect(() => setNotes(originalNotes), [originalNotes]);
......
import { useMemo } from 'react';
import { useLiveQuery } from 'loot-core/client/query-hooks';
import { q } from 'loot-core/shared/query';
import { type NoteEntity } from 'loot-core/types/models';
export function useNotes(id: string) {
const data = useLiveQuery<NoteEntity[]>(
() => q('notes').filter({ id }).select('*'),
[id],
);
return useMemo(() => (data && data.length > 0 ? data[0].note : null), [data]);
}
---
category: Bugfix
authors: [joel-jeremy]
---
Fix account notes not retrieving correctly in mobile.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment