mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-18 12:47:50 +01:00
feat: show warning if topic notes not synced
This commit is contained in:
@@ -8,7 +8,7 @@ import { SIZE } from '../../utils/size';
|
|||||||
import { PressableButton } from '../ui/pressable';
|
import { PressableButton } from '../ui/pressable';
|
||||||
import Paragraph from '../ui/typography/paragraph';
|
import Paragraph from '../ui/typography/paragraph';
|
||||||
|
|
||||||
export const Card = ({ color }) => {
|
export const Card = ({ color, warning }) => {
|
||||||
const colors = useThemeStore(state => state.colors);
|
const colors = useThemeStore(state => state.colors);
|
||||||
color = color ? color : colors.accent;
|
color = color ? color : colors.accent;
|
||||||
|
|
||||||
@@ -16,7 +16,7 @@ export const Card = ({ color }) => {
|
|||||||
const messageBoardState = useMessageStore(state => state.message);
|
const messageBoardState = useMessageStore(state => state.message);
|
||||||
const announcement = useMessageStore(state => state.announcement);
|
const announcement = useMessageStore(state => state.announcement);
|
||||||
|
|
||||||
return !messageBoardState.visible || selectionMode || announcement ? null : (
|
return !messageBoardState.visible || selectionMode || announcement || warning ? null : (
|
||||||
<PressableButton
|
<PressableButton
|
||||||
onPress={messageBoardState.onPress}
|
onPress={messageBoardState.onPress}
|
||||||
type="gray"
|
type="gray"
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import Seperator from '../ui/seperator';
|
|||||||
import { Tip } from '../tip';
|
import { Tip } from '../tip';
|
||||||
import Heading from '../ui/typography/heading';
|
import Heading from '../ui/typography/heading';
|
||||||
import Paragraph from '../ui/typography/paragraph';
|
import Paragraph from '../ui/typography/paragraph';
|
||||||
|
import { notesnook } from '../../../e2e/test.ids';
|
||||||
|
|
||||||
export const Empty = React.memo(
|
export const Empty = React.memo(
|
||||||
({ loading = true, placeholderData, headerProps, type, screen }) => {
|
({ loading = true, placeholderData, headerProps, type, screen }) => {
|
||||||
@@ -48,6 +49,7 @@ export const Empty = React.memo(
|
|||||||
/>
|
/>
|
||||||
{placeholderData.button && (
|
{placeholderData.button && (
|
||||||
<Button
|
<Button
|
||||||
|
testID={notesnook.buttons.add}
|
||||||
type="grayAccent"
|
type="grayAccent"
|
||||||
title={placeholderData.button}
|
title={placeholderData.button}
|
||||||
iconPosition="right"
|
iconPosition="right"
|
||||||
|
|||||||
@@ -58,7 +58,8 @@ const List = ({
|
|||||||
heading: 'Home'
|
heading: 'Home'
|
||||||
},
|
},
|
||||||
screen,
|
screen,
|
||||||
ListHeader
|
ListHeader,
|
||||||
|
warning
|
||||||
}) => {
|
}) => {
|
||||||
const colors = useThemeStore(state => state.colors);
|
const colors = useThemeStore(state => state.colors);
|
||||||
const scrollRef = useRef();
|
const scrollRef = useRef();
|
||||||
@@ -170,6 +171,7 @@ const List = ({
|
|||||||
color={headerProps.color}
|
color={headerProps.color}
|
||||||
type={type}
|
type={type}
|
||||||
screen={screen}
|
screen={screen}
|
||||||
|
warning={warning}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -5,15 +5,35 @@ import { useMessageStore } from '../../../stores/stores';
|
|||||||
import { COLORS_NOTE } from '../../../utils/color-scheme';
|
import { COLORS_NOTE } from '../../../utils/color-scheme';
|
||||||
import { Announcement } from '../../announcements/announcement';
|
import { Announcement } from '../../announcements/announcement';
|
||||||
import { Card } from '../../list/card';
|
import { Card } from '../../list/card';
|
||||||
|
import Paragraph from '../../ui/typography/paragraph';
|
||||||
|
|
||||||
|
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
|
||||||
|
import { SIZE } from '../../../utils/size';
|
||||||
export const Header = React.memo(
|
export const Header = React.memo(
|
||||||
({ type, messageCard = true, color, shouldShow = false, noAnnouncement }) => {
|
({ type, messageCard = true, color, shouldShow = false, noAnnouncement, warning }) => {
|
||||||
const colors = useThemeStore(state => state.colors);
|
const colors = useThemeStore(state => state.colors);
|
||||||
const announcements = useMessageStore(state => state.announcements);
|
const announcements = useMessageStore(state => state.announcements);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{announcements.length !== 0 && !noAnnouncement ? (
|
{warning ? (
|
||||||
|
<View
|
||||||
|
style={{
|
||||||
|
padding: 12,
|
||||||
|
backgroundColor: colors.errorBg,
|
||||||
|
width: '95%',
|
||||||
|
alignSelf: 'center',
|
||||||
|
borderRadius: 5,
|
||||||
|
flexDirection: 'row',
|
||||||
|
alignItems: 'center'
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Icon name="sync-alert" size={SIZE.md} color={colors.red} f />
|
||||||
|
<Paragraph style={{ marginLeft: 5 }} color={colors.red}>
|
||||||
|
{warning.title}
|
||||||
|
</Paragraph>
|
||||||
|
</View>
|
||||||
|
) : announcements.length !== 0 && !noAnnouncement ? (
|
||||||
<Announcement color={color || colors.accent} />
|
<Announcement color={color || colors.accent} />
|
||||||
) : type === 'search' ? null : !shouldShow ? (
|
) : type === 'search' ? null : !shouldShow ? (
|
||||||
<View
|
<View
|
||||||
|
|||||||
@@ -20,19 +20,28 @@ import { tabBarRef } from '../../utils/global-refs';
|
|||||||
import { getNote } from '../editor/Functions';
|
import { getNote } from '../editor/Functions';
|
||||||
|
|
||||||
const getNotes = (params, group = true) => {
|
const getNotes = (params, group = true) => {
|
||||||
if (!params) return [];
|
if (!params)
|
||||||
|
return {
|
||||||
|
notes: [],
|
||||||
|
synced: true
|
||||||
|
};
|
||||||
let notes = [];
|
let notes = [];
|
||||||
|
let isSynced = true;
|
||||||
if (params.type !== 'topic' && params.get !== 'monographs') {
|
if (params.type !== 'topic' && params.get !== 'monographs') {
|
||||||
notes = db.notes[params.get](params.id);
|
notes = db.notes[params.get](params.id);
|
||||||
} else if (params.get === 'monographs') {
|
} else if (params.get === 'monographs') {
|
||||||
notes = db.monographs.all;
|
notes = db.monographs.all;
|
||||||
} else {
|
} else {
|
||||||
notes = db.notebooks.notebook(params.notebookId)?.topics.topic(params.id)?.all;
|
notes = db.notebooks.notebook(params.notebookId)?.topics.topic(params.id)?.all;
|
||||||
|
isSynced = db.notebooks.notebook(params.notebookId)?.topics.topic(params.id)?.synced();
|
||||||
}
|
}
|
||||||
if (!notes) {
|
if (!notes) {
|
||||||
notes = [];
|
notes = [];
|
||||||
}
|
}
|
||||||
return group ? groupArray(notes, db.settings?.getGroupOptions('notes')) : notes;
|
return {
|
||||||
|
notes: group ? groupArray(notes, db.settings?.getGroupOptions('notes')) : notes,
|
||||||
|
synced: isSynced
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
function getAlias(params) {
|
function getAlias(params) {
|
||||||
@@ -46,15 +55,26 @@ function getAlias(params) {
|
|||||||
return alias || '';
|
return alias || '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getIsSynced(params) {
|
||||||
|
if (params.type === 'topic') {
|
||||||
|
let topic = db.notebooks.notebook(params.notebookId)?.topics.topic(params.id);
|
||||||
|
return !topic ? true : topic?.synced();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
export const Notes = ({ route, navigation }) => {
|
export const Notes = ({ route, navigation }) => {
|
||||||
const colors = useThemeStore(state => state.colors);
|
const colors = useThemeStore(state => state.colors);
|
||||||
const params = useRef(route?.params);
|
const params = useRef(route?.params);
|
||||||
const [notes, setNotes] = useState(getNotes(params.current) || []);
|
const [notes, setNotes] = useState(getNotes(params.current).notes || []);
|
||||||
const loading = useNoteStore(state => state.loading);
|
const loading = useNoteStore(state => state.loading);
|
||||||
const alias = getAlias(params);
|
const alias = getAlias(params);
|
||||||
|
const [warning, setWarning] = useState(!getIsSynced(params.current));
|
||||||
|
|
||||||
const onLoad = () => {
|
const onLoad = () => {
|
||||||
let _notes = getNotes(params.current);
|
let data = getNotes(params.current);
|
||||||
|
let _notes = data.notes;
|
||||||
|
setWarning(!data.synced);
|
||||||
setNotes(_notes);
|
setNotes(_notes);
|
||||||
if (!params.current) return;
|
if (!params.current) return;
|
||||||
if (
|
if (
|
||||||
@@ -88,7 +108,6 @@ export const Notes = ({ route, navigation }) => {
|
|||||||
const init = data => {
|
const init = data => {
|
||||||
if (data) params.current = data;
|
if (data) params.current = data;
|
||||||
|
|
||||||
setActionAfterFirstSave();
|
|
||||||
onLoad();
|
onLoad();
|
||||||
Navigation.setHeaderState('NotesPage', params, {
|
Navigation.setHeaderState('NotesPage', params, {
|
||||||
heading:
|
heading:
|
||||||
@@ -101,6 +120,7 @@ export const Notes = ({ route, navigation }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onFocus = () => {
|
const onFocus = () => {
|
||||||
|
setActionAfterFirstSave();
|
||||||
InteractionManager.runAfterInteractions(() => {
|
InteractionManager.runAfterInteractions(() => {
|
||||||
Navigation.routeNeedsUpdate('NotesPage', init);
|
Navigation.routeNeedsUpdate('NotesPage', init);
|
||||||
}, 150);
|
}, 150);
|
||||||
@@ -146,7 +166,7 @@ export const Notes = ({ route, navigation }) => {
|
|||||||
: alias.slice(0, 1).toUpperCase() + alias.slice(1),
|
: alias.slice(0, 1).toUpperCase() + alias.slice(1),
|
||||||
|
|
||||||
get: () => {
|
get: () => {
|
||||||
return getNotes(params.current, false);
|
return getNotes(params.current, false).notes;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -255,6 +275,13 @@ export const Notes = ({ route, navigation }) => {
|
|||||||
listData={notes || []}
|
listData={notes || []}
|
||||||
type="notes"
|
type="notes"
|
||||||
screen="NotesPage"
|
screen="NotesPage"
|
||||||
|
warning={
|
||||||
|
warning
|
||||||
|
? {
|
||||||
|
title: 'Some notes in this topic are not synced'
|
||||||
|
}
|
||||||
|
: null
|
||||||
|
}
|
||||||
refreshCallback={_refreshCallback}
|
refreshCallback={_refreshCallback}
|
||||||
headerProps={headerProps}
|
headerProps={headerProps}
|
||||||
loading={loading}
|
loading={loading}
|
||||||
|
|||||||
Reference in New Issue
Block a user