fix state issues

This commit is contained in:
ammarahm-ed
2022-03-09 17:05:34 +05:00
parent 7cf7dbaa65
commit 763de6db41
5 changed files with 103 additions and 96 deletions

View File

@@ -13,7 +13,8 @@ import { PressableButton } from '../ui/pressable';
import Heading from '../ui/typography/heading'; import Heading from '../ui/typography/heading';
import Paragraph from '../ui/typography/paragraph'; import Paragraph from '../ui/typography/paragraph';
export const ColorSection = () => { export const ColorSection = React.memo(
() => {
const colorNotes = useMenuStore(state => state.colorNotes); const colorNotes = useMenuStore(state => state.colorNotes);
const loading = useNoteStore(state => state.loading); const loading = useNoteStore(state => state.loading);
const setColorNotes = useMenuStore(state => state.setColorNotes); const setColorNotes = useMenuStore(state => state.setColorNotes);
@@ -28,7 +29,9 @@ export const ColorSection = () => {
let alias = db.colors.alias(item.id); let alias = db.colors.alias(item.id);
return <ColorItem key={item.id} alias={alias} item={item} index={index} />; return <ColorItem key={item.id} alias={alias} item={item} index={index} />;
}); });
}; },
() => true
);
const ColorItem = React.memo( const ColorItem = React.memo(
({ item, index, alias }) => { ({ item, index, alias }) => {

View File

@@ -20,7 +20,8 @@ export const SideMenu = React.memo(
const colors = useThemeStore(state => state.colors); const colors = useThemeStore(state => state.colors);
const deviceMode = useSettingStore(state => state.deviceMode); const deviceMode = useSettingStore(state => state.deviceMode);
const insets = useSafeAreaInsets(); const insets = useSafeAreaInsets();
const user = useUserStore(state => state.user); const subscriptionType = useUserStore(state => state.user?.subscription?.type);
console.log(subscriptionType);
const noTextMode = false; const noTextMode = false;
const BottomItemsList = [ const BottomItemsList = [
@@ -98,9 +99,8 @@ export const SideMenu = React.memo(
paddingHorizontal: 12 paddingHorizontal: 12
}} }}
> >
{!user || {subscriptionType === SUBSCRIPTION_STATUS.TRIAL ||
user?.subscription?.type === SUBSCRIPTION_STATUS.TRIAL || subscriptionType === SUBSCRIPTION_STATUS.BASIC ? (
user?.subscription?.type === SUBSCRIPTION_STATUS.BASIC ? (
<MenuItem testID={pro.name} key={pro.name} item={pro} index={0} ignore={true} /> <MenuItem testID={pro.name} key={pro.name} item={pro} index={0} ignore={true} />
) : null} ) : null}

View File

@@ -17,7 +17,8 @@ import SheetWrapper from '../ui/sheet';
import Heading from '../ui/typography/heading'; import Heading from '../ui/typography/heading';
import Paragraph from '../ui/typography/paragraph'; import Paragraph from '../ui/typography/paragraph';
export const TagsSection = () => { export const TagsSection = React.memo(
() => {
const menuPins = useMenuStore(state => state.menuPins); const menuPins = useMenuStore(state => state.menuPins);
const loading = useNoteStore(state => state.loading); const loading = useNoteStore(state => state.loading);
const setMenuPins = useMenuStore(state => state.setMenuPins); const setMenuPins = useMenuStore(state => state.setMenuPins);
@@ -66,9 +67,8 @@ export const TagsSection = () => {
} }
Navigation.closeDrawer(); Navigation.closeDrawer();
}; };
const renderItem = ({ item, index }) => { const renderItem = ({ item, index }) => {
let alias = item.type === 'tag' ? db.tags.alias(item.title) : item.title; let alias = item ? (item.type === 'tag' ? db.tags.alias(item.title) : item.title) : null;
return <PinItem item={item} index={index} alias={alias} onPress={onPress} />; return <PinItem item={item} index={index} alias={alias} onPress={onPress} />;
}; };
@@ -98,13 +98,15 @@ export const TagsSection = () => {
/> />
</View> </View>
); );
}; },
() => true
);
export const PinItem = React.memo( export const PinItem = React.memo(
({ item, index, onPress, placeholder, alias }) => { ({ item, index, onPress, placeholder, alias }) => {
const colors = useThemeStore(state => state.colors); const colors = useThemeStore(state => state.colors);
const setMenuPins = useMenuStore(state => state.setMenuPins); const setMenuPins = useMenuStore(state => state.setMenuPins);
alias = item.type === 'tag' ? db.tags.alias(item.title) : item.title; alias = !item ? '' : item.type === 'tag' ? db.tags.alias(item.title) : item.title;
const [visible, setVisible] = useState(false); const [visible, setVisible] = useState(false);
const [headerTextState, setHeaderTextState] = useState(null); const [headerTextState, setHeaderTextState] = useState(null);
const color = headerTextState?.id === item.id ? colors.accent : colors.pri; const color = headerTextState?.id === item.id ? colors.accent : colors.pri;
@@ -238,6 +240,7 @@ export const PinItem = React.memo(
); );
}, },
(prev, next) => { (prev, next) => {
if (!next.item) return false;
if (prev.alias !== next.alias) return false; if (prev.alias !== next.alias) return false;
if (prev.item?.dateModified !== next.item?.dateModified) return false; if (prev.item?.dateModified !== next.item?.dateModified) return false;
if (prev.item?.id !== next.item?.id) return false; if (prev.item?.id !== next.item?.id) return false;

View File

@@ -299,7 +299,6 @@ export const useActions = ({ close = () => {}, item }) => {
try { try {
if (isPinnedToMenu) { if (isPinnedToMenu) {
await db.settings.unpin(item.id); await db.settings.unpin(item.id);
return;
} else { } else {
if (item.type === 'topic') { if (item.type === 'topic') {
await db.settings.pin(item.type, { await db.settings.pin(item.type, {

View File

@@ -165,6 +165,7 @@ export const useAppEvents = () => {
}; };
const onSyncComplete = async () => { const onSyncComplete = async () => {
console.log('sync complete');
initialize(); initialize();
setLastSynced(await db.lastSynced()); setLastSynced(await db.lastSynced());
if (getNote()) { if (getNote()) {
@@ -219,6 +220,7 @@ export const useAppEvents = () => {
}; };
const onRequestPartialSync = async (full, force) => { const onRequestPartialSync = async (full, force) => {
console.log('auto sync request', full, force);
try { try {
if (full || force) { if (full || force) {
Sync.run('global', force, full); Sync.run('global', force, full);