Skip to content

Commit

Permalink
Revert "Revert "bookmark changes""
Browse files Browse the repository at this point in the history
This reverts commit 15016ff.
  • Loading branch information
Anthonyp0329 committed Mar 12, 2024
1 parent 15016ff commit b373efc
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 111 deletions.
2 changes: 0 additions & 2 deletions dfm-sideline-sidekick-app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ type RootStackParamList = {
type StackNavigation = StackNavigationProp<RootStackParamList>;
const Stack = createNativeStackNavigator<RootStackParamList>();



const BottomNavBarComponent = () => {
const navigation = useNavigation<StackNavigation>();

Expand Down
2 changes: 1 addition & 1 deletion dfm-sideline-sidekick-app/components/bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const BottomNavBar: React.FC<{ items: NavItem[] }> = ({ items }) => {
<CircleIcon fillColor={selectedItemId === item.id ? "#001F3F" : "#C0C8CB"} />
</View>
) : item.icon === "bookmark" ? (
<BookmarkIcon fillColor={selectedItemId === item.id ? "#001F3F" : "#C0C8CB"}/>
<BookmarkIcon fillColor={selectedItemId === item.id ? "#001F3F" : "#C0C8CB"} />
) : (
<GeneralPrinciplesIcon fillColor={selectedItemId === item.id ? "#001F3F" : "#C0C8CB"} />
)}
Expand Down
56 changes: 28 additions & 28 deletions dfm-sideline-sidekick-app/components/bookmark.tsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
import React, { useState } from "react";
import { TouchableOpacity } from "react-native";

import { BookmarkIcon, BookmarkTag } from '../icons/bookmarkIcon';


import {createBookmark, deleteBookmark, getAllBookmarks} from './bookmarkRoutes'
import { BookmarkIcon, BookmarkTag } from "../icons/bookmarkIcon";

import { createBookmark, deleteBookmark } from "./bookmarkRoutes";

type bookmarkProps = {
PageName: string;
};
item: object | undefined;
};

export const Bookmark: React.FC<bookmarkProps> = ({ PageName }) =>{
const [selectedItemId, setSelectedItemId] = useState(0);
export const Bookmark: React.FC<bookmarkProps> = ({ item }) => {
const [selectedItemId, setSelectedItemId] = useState(0);

const handleBookmarkClick = () => {
selectedItemId === 0 ? (
createBookmark(PageName),
setSelectedItemId(1)
) : (
getAllBookmarks(),
deleteBookmark(PageName),
setSelectedItemId(0)
);
const handleBookmarkClick = () => {
if (selectedItemId === 0) {
createBookmark(item);
setSelectedItemId(1);
} else {
deleteBookmark(item);
setSelectedItemId(0);
};

return (
<TouchableOpacity
onPress={() => {
handleBookmarkClick();
}}
>
{selectedItemId === 1 ? <BookmarkTag fillColor={"#001F3F"}/>: <BookmarkIcon fillColor={"#001F3F"}/>}

</TouchableOpacity>
);
};

return (
<TouchableOpacity
onPress={() => {
handleBookmarkClick();
}}
>
{selectedItemId === 1 ? (
<BookmarkTag fillColor={"#001F3F"} />
) : (
<BookmarkIcon fillColor={"#001F3F"} />
)}
</TouchableOpacity>
);
};
64 changes: 31 additions & 33 deletions dfm-sideline-sidekick-app/components/bookmarkRoutes.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,56 @@
// import {AsyncStorage} from '@react-native-async-storage/async-storage';
//
const AsyncStorage = require("@react-native-async-storage/async-storage").default;

Check failure on line 3 in dfm-sideline-sidekick-app/components/bookmarkRoutes.js

View workflow job for this annotation

GitHub Actions / Frontend lint and style check

Require statement not part of import statement

Check failure on line 3 in dfm-sideline-sidekick-app/components/bookmarkRoutes.js

View workflow job for this annotation

GitHub Actions / Frontend lint and style check

'require' is not defined

const AsyncStorage = require('@react-native-async-storage/async-storage').default;

export const createBookmark = async (name) => {
export const createBookmark = (item) => {
try {
let bookmarks = JSON.parse(await AsyncStorage.getItem('bookmarks')) || [];
const exists = bookmarks.includes(name);
let bookmarks = JSON.parse(await AsyncStorage.getItem("bookmarks")) || [];

Check failure on line 7 in dfm-sideline-sidekick-app/components/bookmarkRoutes.js

View workflow job for this annotation

GitHub Actions / Frontend lint and style check

Unsafe assignment of an `any` value
const exists = bookmarks.includes(item);

Check failure on line 8 in dfm-sideline-sidekick-app/components/bookmarkRoutes.js

View workflow job for this annotation

GitHub Actions / Frontend lint and style check

Unsafe assignment of an `any` value

Check failure on line 8 in dfm-sideline-sidekick-app/components/bookmarkRoutes.js

View workflow job for this annotation

GitHub Actions / Frontend lint and style check

Unsafe call of an `any` typed value

Check failure on line 8 in dfm-sideline-sidekick-app/components/bookmarkRoutes.js

View workflow job for this annotation

GitHub Actions / Frontend lint and style check

Unsafe member access .includes on an `any` value
if (exists) {
throw new Error('Bookmark already exists!');
throw new Error("Bookmark already exists!");
}
bookmarks.push(name);
console.log(name);
bookmarks.push(item);

Check failure on line 12 in dfm-sideline-sidekick-app/components/bookmarkRoutes.js

View workflow job for this annotation

GitHub Actions / Frontend lint and style check

Unsafe call of an `any` typed value

Check failure on line 12 in dfm-sideline-sidekick-app/components/bookmarkRoutes.js

View workflow job for this annotation

GitHub Actions / Frontend lint and style check

Unsafe member access .push on an `any` value
console.log(item);
console.log(bookmarks);
await AsyncStorage.setItem('bookmarks', JSON.stringify(bookmarks));
console.log('Bookmark created:', name);
await AsyncStorage.setItem("bookmarks", JSON.stringify(bookmarks));
console.log("Bookmark created:", name);
} catch (error) {
throw new Error('Error creating bookmark: ' + error.message);
throw new Error("Error creating bookmark: " + error.message);

Check failure on line 18 in dfm-sideline-sidekick-app/components/bookmarkRoutes.js

View workflow job for this annotation

GitHub Actions / Frontend lint and style check

Unsafe member access .message on an `any` value
}
}
};

export const deleteBookmark = async (name) => {
export const deleteBookmark = (item) => {
try {
const existingBookmarks = JSON.parse(await AsyncStorage.getItem('bookmarks')) || [];
const index = existingBookmarks.findIndex((bookmark) => bookmark === name);
const existingBookmarks = JSON.parse(await AsyncStorage.getItem("bookmarks")) || [];
const index = existingBookmarks.findIndex((bookmark) => bookmark.title === item.title);
if (index !== -1) {
existingBookmarks.splice(index, 1);
await AsyncStorage.setItem('bookmarks', JSON.stringify(existingBookmarks));
console.log("Bookmark deleted!")
await AsyncStorage.setItem("bookmarks", JSON.stringify(existingBookmarks));
console.log("Bookmark deleted!");
} else {
console.log('Bookmark not found!');
console.log("Bookmark not found!");
}
} catch (error) {
console.error('Error deleting bookmark:', error);
console.error("Error deleting bookmark:", error);
}
}

};

export const getAllBookmarks = async () => {
try {
const existingBookmarks = JSON.parse(await AsyncStorage.getItem('bookmarks')) || [];
const existingBookmarks = JSON.parse(await AsyncStorage.getItem("bookmarks")) || [];
return existingBookmarks;
} catch (error) {
console.error('Error getting bookmarks:', error);
console.error("Error getting bookmarks:", error);
return [];
}
}
};

// Function for testing to clear all bookmarks from AsyncStorage
// export const clearBookmarks = async () => {
// try {
// await AsyncStorage.removeItem('bookmarks');
// console.log('Bookmarks cleared successfully.');
// } catch (error) {
// console.error('Error clearing bookmarks:', error);
// }
// };

export const clearBookmarks = async () => {
try {
await AsyncStorage.removeItem("bookmarks");
console.log("Bookmarks cleared successfully.");
} catch (error) {
console.error("Error clearing bookmarks:", error);
}
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/* eslint-disable @typescript-eslint/no-unsafe-return */
import NetInfo from "@react-native-community/netinfo";

Expand Down
10 changes: 4 additions & 6 deletions dfm-sideline-sidekick-app/icons/bookmarkIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import PropTypes from "prop-types";
import { View } from "react-native";
import { Path, Svg } from "react-native-svg";

export const BookmarkIcon = ({ fillColor}) => {
export const BookmarkIcon = ({ fillColor }) => {
return (
<View>
<Svg width="21" height="27" viewBox="0 0 21 27" >
<Svg width="21" height="27" viewBox="0 0 21 27">
<Path
id="Vector"
d="M0 26.757V2.973C0 2.15543 0.291354 1.45578 0.874063 0.874063C1.45677 0.292346 2.15642 0.000991001 2.973 0H17.838C18.6556 0 19.3557 0.291355 19.9385 0.874063C20.5212 1.45677 20.812 2.15642 20.811 2.973V26.757L10.4055 22.2975L0 26.757ZM2.973 22.2232L10.4055 19.0272L17.838 22.2232V2.973H2.973V22.2232Z"
Expand All @@ -17,10 +17,10 @@ export const BookmarkIcon = ({ fillColor}) => {
);
};

export const BookmarkTag = ({ fillColor}) => {
export const BookmarkTag = ({ fillColor }) => {
return (
<View>
<Svg width="21" height="27" viewBox="0 0 21 27" >
<Svg width="21" height="27" viewBox="0 0 21 27">
<Path
id="Vector"
d="M2.973 0C2.15642 0 1.45677 0.292346 0.874063 0.874063C0.291354 1.45578 0 2.15543 0 2.973V26.757L10.4055 22.2975L20.811 26.757V2.973C20.812 2.15642 20.5212 1.45677 19.9385 0.874063C19.3557 0.291354 18.6556 0 17.838 0H2.973ZM10.4055 19.0272L17.838 22.2232V2.973H2.973V22.2232L10.4055 19.0272Z"
Expand All @@ -38,5 +38,3 @@ BookmarkIcon.propTypes = {
BookmarkTag.propTypes = {
fillColor: PropTypes.string.isRequired,
};


11 changes: 0 additions & 11 deletions dfm-sideline-sidekick-app/pages/BookmarkPage.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion dfm-sideline-sidekick-app/pages/ConditionSectionStyles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default StyleSheet.create({
marginTop: 16,
},
topRightContainer: {
position: 'absolute',
position: "absolute",
top: 80,
right: 0,
padding: 10,
Expand Down
3 changes: 1 addition & 2 deletions dfm-sideline-sidekick-app/pages/ConditionsSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import styles from "./ConditionSectionStyles";

import type { Emergency } from "../emergencies";


export type RootStackParamList = {
// Define the parameters for your screens here
Conditions: { emergency: Emergency }; // Example parameter
Expand Down Expand Up @@ -125,7 +124,7 @@ export default function ConditionsSection({ route, navigation }: Props) {
return (
<SafeAreaView style={styles.container}>
<View style={styles.topRightContainer}>
<Bookmark PageName="Conditions Section Page" />
<Bookmark item={emergency} />
</View>
<ScrollView alwaysBounceHorizontal={false} contentContainerStyle={{ flexGrow: 1 }}>
<TouchableOpacity
Expand Down
1 change: 0 additions & 1 deletion dfm-sideline-sidekick-app/pages/EmergencyCare.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import AntIcon from "react-native-vector-icons/AntDesign";
import BulletPoint from "../components/BulletPoint";
import { Bookmark } from "../components/bookmark";


import styles from "./generalPrinciplesStyles";

const EmergencyCare = () => {
Expand Down
16 changes: 8 additions & 8 deletions dfm-sideline-sidekick-app/pages/HomePage.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Text, View } from 'react-native';
import { Text, View } from "react-native";

export const HomePage = () => {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Home Dummy Page</Text>
</View>
);
}
return (
<View style={{ flex: 1, alignItems: "center", justifyContent: "center" }}>
<Text>Home Dummy Page</Text>
</View>
);
};

export default HomePage;
export default HomePage;
1 change: 1 addition & 0 deletions dfm-sideline-sidekick-app/pages/SearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const SearchPage: React.FC = () => {
const allDocuments = [...emergencies, ...generalPrinciples];
const matchedDocuments = searchDocuments(allDocuments, text).map((doc) => ({
...doc,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
_id: doc._id ?? "fallback-id",
subtitle:
doc.subtitle ?? "Lorem ipsum dolor sit amet, consectetur adip iscing elit, sed do.",
Expand Down
5 changes: 2 additions & 3 deletions dfm-sideline-sidekick-app/pages/generalPrinciples.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const GeneralPrinciples: React.FC<GeneralProps> = ({ route, navigation }) => {
<View style={styles.container}>
<ScrollView alwaysBounceHorizontal={false} contentContainerStyle={{ flexGrow: 1 }}>
<View style={styles.topRightContainer}>
<Bookmark PageName="Emergency Page" />
<Bookmark item={params.contentProp} />
</View>
<TouchableOpacity
onPress={() => {
Expand All @@ -59,8 +59,7 @@ const GeneralPrinciples: React.FC<GeneralProps> = ({ route, navigation }) => {
>
<AntIcon name="close" style={styles.button} />
</TouchableOpacity>
<Text style={styles.title}>{params.titleProp}</Text>
<Text style={styles.subTitle}>{params.contentProp.title}</Text>
<Text style={styles.title}>{params.contentProp.title}</Text>
<BulletPoint content={params.contentProp.content} />
</ScrollView>
</View>
Expand Down
4 changes: 2 additions & 2 deletions dfm-sideline-sidekick-app/pages/generalPrinciplesStyles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ const styles = StyleSheet.create({
paddingTop: 10,
},
topRightContainer: {
position: 'absolute',
top: 80,
position: "absolute",
top: 28,
right: 0,
padding: 10,
zIndex: 1,
Expand Down
24 changes: 12 additions & 12 deletions dfm-sideline-sidekick-app/styles/NavBar.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { StyleSheet } from "react-native";

const styles = StyleSheet.create({
bottomBar: {
flexDirection: 'row',
justifyContent: 'space-around',
alignItems: 'center',
backgroundColor: '#f0f0f0',
padding: 8,
position: 'absolute',
bottom: 0,
left: 0,
right: 0,
height: 79
},
bottomBar: {
flexDirection: "row",
justifyContent: "space-around",
alignItems: "center",
backgroundColor: "#f0f0f0",
padding: 8,
position: "absolute",
bottom: 0,
left: 0,
right: 0,
height: 79,
},
});

export default styles;

0 comments on commit b373efc

Please sign in to comment.