Skip to content

Commit

Permalink
mobile: fix selection is not reset when switching topics
Browse files Browse the repository at this point in the history
  • Loading branch information
ammarahm-ed committed Sep 22, 2023
1 parent 528c0a1 commit 7bac3c1
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 20 deletions.
5 changes: 4 additions & 1 deletion apps/mobile/app/common/filesystem/io.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ export async function migrateFilesFromCache() {
await createCacheDir();
const migratedFilesPath = cacheDir + "/.migrated_1";
const migrated = await RNFetchBlob.fs.exists(migratedFilesPath);
if (migrated) return;
if (migrated) {
console.log("Files migrated already");
return;
}

let files = await RNFetchBlob.fs.ls(cacheDir);
console.log("Files to migrate:", files.join(","));
Expand Down
2 changes: 1 addition & 1 deletion apps/mobile/app/components/list/card.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const Card = ({ color, warning }) => {
</Paragraph>
<Paragraph
style={{
flexWrap: "no-wrap",
flexWrap: "nowrap",
flexShrink: 1
}}
color={colors.primary.heading}
Expand Down
44 changes: 29 additions & 15 deletions apps/mobile/app/components/sheets/topic-sheet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { useThemeColors } from "@notesnook/theme";
import qclone from "qclone";
import React, {
createContext,
Expand All @@ -26,7 +27,7 @@ import React, {
useRef,
useState
} from "react";
import { RefreshControl, View } from "react-native";
import { RefreshControl, useWindowDimensions, View } from "react-native";
import ActionSheet, {
ActionSheetRef,
FlatList
Expand All @@ -45,7 +46,6 @@ import {
import useNavigationStore, {
NotebookScreenParams
} from "../../../stores/use-navigation-store";
import { useThemeColors } from "@notesnook/theme";
import {
eOnNewTopicAdded,
eOnTopicSheetUpdate,
Expand All @@ -54,18 +54,17 @@ import {
import { normalize, SIZE } from "../../../utils/size";
import { GroupHeader, NotebookType, TopicType } from "../../../utils/types";

import { getTotalNotes } from "@notesnook/common";
import { groupArray } from "@notesnook/core/dist/utils/grouping";
import Config from "react-native-config";
import Icon from "react-native-vector-icons/MaterialCommunityIcons";
import { notesnook } from "../../../../e2e/test.ids";
import { MMKV } from "../../../common/database/mmkv";
import { openEditor } from "../../../screens/notes/common";
import { getTotalNotes } from "@notesnook/common";
import { useSelectionStore } from "../../../stores/use-selection-store";
import { deleteItems } from "../../../utils/functions";
import { presentDialog } from "../../dialog/functions";
import { Properties } from "../../properties";
import Sort from "../sort";
import { useSelectionStore } from "../../../stores/use-selection-store";

type ConfigItem = { id: string; type: string };
class TopicSheetConfig {
Expand Down Expand Up @@ -108,7 +107,8 @@ export const TopicsSheet = () => {
)
: []
);

const currentItem = useRef<string>();
const { fontScale } = useWindowDimensions();
const [groupOptions, setGroupOptions] = useState(
db.settings?.getGroupOptions("topics")
);
Expand Down Expand Up @@ -206,6 +206,11 @@ export const TopicsSheet = () => {
if (canShow) {
setTimeout(() => {
const id = isTopic ? currentScreen?.notebookId : currentScreen?.id;
if (currentItem.current !== id) {
setSelection([]);
setEnabled(false);
}
currentItem.id = id;
const notebook = db.notebooks?.notebook(id as string)?.data;
const snapPoint = isTopic
? 0
Expand All @@ -226,6 +231,8 @@ export const TopicsSheet = () => {
}
}, 300);
} else {
setSelection([]);
setEnabled(false);
ref.current?.hide();
}
}, [
Expand Down Expand Up @@ -329,7 +336,9 @@ export const TopicsSheet = () => {
{enabled ? (
<IconButton
customStyle={{
marginLeft: 10
marginLeft: 10,
width: 40 * fontScale,
height: 40 * fontScale
}}
onPress={async () => {
//@ts-ignore
Expand Down Expand Up @@ -365,8 +374,8 @@ export const TopicsSheet = () => {
color={colors.primary.icon}
size={22}
customStyle={{
width: 40,
height: 40
width: 40 * fontScale,
height: 40 * fontScale
}}
/>
<IconButton
Expand All @@ -376,8 +385,8 @@ export const TopicsSheet = () => {
color={colors.primary.icon}
size={22}
customStyle={{
width: 40,
height: 40
width: 40 * fontScale,
height: 40 * fontScale
}}
/>

Expand All @@ -395,8 +404,8 @@ export const TopicsSheet = () => {
color={colors.primary.icon}
size={22}
customStyle={{
width: 40,
height: 40
width: 40 * fontScale,
height: 40 * fontScale
}}
/>
</>
Expand Down Expand Up @@ -470,6 +479,7 @@ const TopicItem = ({
selection.selection.findIndex((selected) => selected.id === item.id) > -1;
const isFocused = screen.id === item.id;
const notesCount = getTotalNotes(item);
const { fontScale } = useWindowDimensions();

return (
<PressableButton
Expand Down Expand Up @@ -506,6 +516,10 @@ const TopicItem = ({
<IconButton
size={SIZE.lg}
color={isSelected ? colors.selected.icon : colors.primary.icon}
top={0}
left={0}
bottom={0}
right={0}
name={
isSelected
? "check-circle-outline"
Expand All @@ -525,8 +539,8 @@ const TopicItem = ({
<IconButton
name="dots-horizontal"
customStyle={{
width: 40,
height: 40
width: 40 * fontScale,
height: 40 * fontScale
}}
testID={notesnook.ids.notebook.menu}
onPress={() => {
Expand Down
2 changes: 1 addition & 1 deletion apps/mobile/app/stores/use-selection-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const useSelectionStore = create<SelectionStore>((set, get) => ({

set({
selectedItemsList: selectedItems,
selectionMode: get().selectionMode
selectionMode: selectedItems.length === 0 ? false : get().selectionMode
});
},
clearSelection: () => {
Expand Down
4 changes: 2 additions & 2 deletions apps/mobile/native/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ PODS:
- ReactCommon/turbomodule/core
- react-native-share-extension (2.5.6):
- React
- react-native-sodium (1.5.2):
- react-native-sodium (1.5.4):
- React
- react-native-webview (11.26.1):
- React-Core
Expand Down Expand Up @@ -882,7 +882,7 @@ SPEC CHECKSUMS:
react-native-pdf: 33c622cbdf776a649929e8b9d1ce2d313347c4fa
react-native-safe-area-context: 36cc67648134e89465663b8172336a19eeda493d
react-native-share-extension: df66a2ee48a62277d79898375e2142bde0782063
react-native-sodium: 7d2bbb9ca840dc58d63f661b2ff733a38170fec5
react-native-sodium: 955bb0dc3ea05f8ea06d5e96cb89d1be7b5d7681
react-native-webview: 9f111dfbcfc826084d6c507f569e5e03342ee1c1
React-NativeModulesApple: 1d81d927ef1a67a3545a01e14c2e98500bf9b199
React-perflogger: 684a11499a0589cc42135d6d5cc04d0e4e0e261a
Expand Down

0 comments on commit 7bac3c1

Please sign in to comment.