-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
15 changed files
with
91 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 GitHub Actions / Frontend lint and style check
|
||
|
||
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")) || []; | ||
const exists = bookmarks.includes(item); | ||
Check failure on line 8 in dfm-sideline-sidekick-app/components/bookmarkRoutes.js GitHub Actions / Frontend lint and style check
Check failure on line 8 in dfm-sideline-sidekick-app/components/bookmarkRoutes.js GitHub Actions / Frontend lint and style check
|
||
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 GitHub Actions / Frontend lint and style check
|
||
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); | ||
} | ||
} | ||
}; | ||
|
||
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); | ||
} | ||
}; |
1 change: 0 additions & 1 deletion
1
dfm-sideline-sidekick-app/download/connection/checkConnection.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |