Skip to content

Commit 1b7f7e3

Browse files
author
Neelesh Ranjan Jha
committed
edit working, day edit copies
1 parent 64fad5f commit 1b7f7e3

File tree

7 files changed

+286
-77
lines changed

7 files changed

+286
-77
lines changed

App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default function App() {
3030
setLoading(true);
3131
await AsyncStorage.getAllKeys()
3232
.then(async (res) => {
33-
// await AsyncStorage.clear()
33+
await AsyncStorage.clear()
3434
if(res.length == 0)
3535
{
3636
createEmptyStorage();

src/components/ClassList/index.jsx

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import React, { useEffect, useState } from "react";
2-
import { View, Text, StyleSheet, FlatList } from "react-native";
2+
import { View, Text, StyleSheet, FlatList, TouchableWithoutFeedback } from "react-native";
33
import { ListItem } from "react-native-elements";
44
import {
55
widthPercentageToDP as wp,
66
heightPercentageToDP as hp,
77
} from "react-native-responsive-screen";
8-
import { useIsFocused } from "@react-navigation/native";
8+
import { useIsFocused, useNavigation } from "@react-navigation/native";
99
import AsyncStorage from "@react-native-async-storage/async-storage";
1010

1111
import Loading from "../Loader";
@@ -14,9 +14,11 @@ import { msToHuman } from "./helper";
1414

1515
export default function ClassList({ name }) {
1616
const isFocused = useIsFocused();
17-
// const [loading, setLoading] = useState(false);
17+
const [modalVisible, setVisible] = useState(false);
1818
const [classList, setClassList] = React.useState([]);
1919

20+
const navigation = useNavigation();
21+
2022
async function getClassList(name) {
2123
// console.log(classList)
2224
await AsyncStorage.getItem(name)
@@ -34,31 +36,43 @@ export default function ClassList({ name }) {
3436

3537
function renderList(l) {
3638
return (
37-
<ListItem
38-
containerStyle={[{ backgroundColor: "#26de81" }, styles.container]}
39-
>
40-
<View>
41-
<Text style={styles.textColor}>{msToHuman(l.item.from)}</Text>
42-
<Text style={styles.textColor}>{msToHuman(l.item.to)}</Text>
43-
</View>
44-
<ListItem.Content containerStyle={styles.content}>
45-
<ListItem.Title style={styles.textColor}>
46-
{l.item.subname}
47-
</ListItem.Title>
48-
<ListItem.Subtitle style={styles.textColor}>
49-
{l.item.type}
50-
</ListItem.Subtitle>
51-
</ListItem.Content>
52-
<View>
53-
<Text style={styles.textColor}>{l.item.slot}</Text>
54-
</View>
55-
</ListItem>
39+
<TouchableWithoutFeedback>
40+
<ListItem
41+
containerStyle={[{ backgroundColor: "#26de81" }, styles.container]}
42+
onLongPress={() =>
43+
navigation.navigate("editclass", {
44+
Uid: l.item.uid,
45+
From: l.item.from,
46+
To: l.item.to,
47+
Subname: l.item.subname,
48+
Type: l.item.type,
49+
Slot: l.item.slot,
50+
})
51+
}
52+
>
53+
<View>
54+
<Text style={styles.textColor}>{msToHuman(l.item.from)}</Text>
55+
<Text style={styles.textColor}>{msToHuman(l.item.to)}</Text>
56+
</View>
57+
<ListItem.Content containerStyle={styles.content}>
58+
<ListItem.Title style={styles.textColor}>
59+
{l.item.subname}
60+
</ListItem.Title>
61+
<ListItem.Subtitle style={styles.textColor}>
62+
{l.item.type}
63+
</ListItem.Subtitle>
64+
</ListItem.Content>
65+
<View>
66+
<Text style={styles.textColor}>{l.item.slot}</Text>
67+
</View>
68+
</ListItem>
69+
</TouchableWithoutFeedback>
5670
);
5771
}
5872

5973
if (classList != null) {
6074
if (classList.length != 0) {
61-
console.log("not empty list");
75+
// console.log("not empty list");
6276
return (
6377
<FlatList
6478
data={classList}
@@ -67,11 +81,11 @@ export default function ClassList({ name }) {
6781
></FlatList>
6882
);
6983
} else {
70-
console.log(" empty list");
84+
// console.log(" empty list");
7185
return null;
7286
}
7387
} else {
74-
console.log(" empty list");
88+
// console.log(" empty list");
7589
return null;
7690
}
7791
}

src/routes/rootNav.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import React from 'react';
2-
import { TouchableOpacity,Alert } from 'react-native';
2+
import { TouchableOpacity } from 'react-native';
33
import { createNativeStackNavigator } from '@react-navigation/native-stack';
44
import { Icon } from 'react-native-elements';
55
import {widthPercentageToDP as wp, heightPercentageToDP as hp} from 'react-native-responsive-screen';
66

77
import TimeTable from '../screens/TimeTable';
88
import AddClass from '../screens/AddClass';
9+
import EditClass from '../screens/EditClass';
910

1011
const Stack = createNativeStackNavigator();
1112

@@ -28,7 +29,8 @@ export default function RootNav(){
2829
</>
2930
)
3031
})}/>
31-
<Stack.Screen name="addclass" component={AddClass} options={() => ({ headerTitle: 'Add Class'})}/>
32+
<Stack.Screen name="addclass" component={AddClass} options={{ title: 'Add Class'}}/>
33+
<Stack.Screen name="editclass" component={EditClass} options={{ title: 'Edit Class'}}/>
3234
</Stack.Navigator>
3335
);
3436
}

src/screens/AddClass/helper.js

Lines changed: 37 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import AsyncStorage from "@react-native-async-storage/async-storage";
22
import { Alert } from "react-native";
3-
import uuid from 'react-native-uuid';
3+
import uuid from "react-native-uuid";
44

55
export async function addToStorage(
66
className,
@@ -11,48 +11,43 @@ export async function addToStorage(
1111
fromTime,
1212
navigation
1313
) {
14-
// console.log(className)
15-
// console.log(slot)
16-
// console.log(type)
17-
// console.log(day)
18-
// console.log(toTime)
19-
// console.log(fromTime)
20-
// const uid = uuidv4();
21-
let arr = await AsyncStorage.getItem(day);
22-
// console.log(arr);
23-
const data = [
24-
{
25-
uid: uuid.v4(),
26-
subname: className,
27-
slot: slot,
28-
type: type,
29-
from: fromTime,
30-
to: toTime,
31-
},
32-
];
33-
34-
arr = JSON.parse(arr).concat(data);
35-
36-
await AsyncStorage.setItem(day, JSON.stringify(arr))
37-
.then(() => {
38-
console.log("added to async storage");
39-
Alert.alert("Success!", "Class Added Successfully!", [
14+
let arr = await AsyncStorage.getItem(day)
15+
.then(async () => {
16+
const data = [
4017
{
41-
text: "Ok",
42-
onPress: () => {
43-
console.log("clearing values....");
44-
navigation.navigate("timetable");
45-
},
18+
uid: uuid.v4(),
19+
subname: className,
20+
slot: slot,
21+
type: type,
22+
from: fromTime,
23+
to: toTime,
4624
},
47-
]);
25+
];
26+
27+
arr = JSON.parse(arr).concat(data);
28+
29+
await AsyncStorage.setItem(day, JSON.stringify(arr))
30+
.then(() => {
31+
console.log("added to async storage");
32+
Alert.alert("Success!", "Class Added Successfully!", [
33+
{
34+
text: "Ok",
35+
onPress: () => {
36+
console.log("clearing values....");
37+
navigation.navigate("timetable");
38+
},
39+
},
40+
]);
41+
})
42+
.catch((e) => {
43+
console.log("failed to store..");
44+
Alert.alert("Failed!", e, [
45+
{
46+
text: "Retry",
47+
onPress: () => console.log("failed..."),
48+
},
49+
]);
50+
});
4851
})
49-
.catch((e) => {
50-
console.log("failed to store..");
51-
Alert.alert("Failed!", e, [
52-
{
53-
text: "Retry",
54-
onPress: () => console.log("failed..."),
55-
},
56-
]);
57-
});
52+
.catch((e) => console.log(e));
5853
}

src/screens/EditClass/helper.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import AsyncStorage from "@react-native-async-storage/async-storage";
2+
import { Alert } from "react-native";
3+
4+
export async function addToStorage(
5+
uid,
6+
className,
7+
slot,
8+
type,
9+
day,
10+
toTime,
11+
fromTime,
12+
navigation
13+
) {
14+
var arr = await AsyncStorage.getItem(day)
15+
.then(async () => {
16+
const data = {
17+
uid: uid,
18+
subname: className,
19+
slot: slot,
20+
type: type,
21+
from: fromTime,
22+
to: toTime,
23+
};
24+
25+
arr = JSON.parse(arr);
26+
let objIndex = arr.findIndex((obj) => obj.uid == uid);
27+
console.log(objIndex);
28+
if (objIndex != -1) {
29+
arr[objIndex] = data;
30+
} else {
31+
arr = arr.concat(data);
32+
33+
}
34+
35+
await AsyncStorage.setItem(day, JSON.stringify(arr))
36+
.then(() => {
37+
console.log(arr);
38+
console.log("added to async storage");
39+
Alert.alert("Success!", "Class Added Successfully!", [
40+
{
41+
text: "Ok",
42+
onPress: () => {
43+
console.log("clearing values....");
44+
navigation.navigate("timetable");
45+
},
46+
},
47+
]);
48+
})
49+
.catch((e) => {
50+
console.log("failed to store..");
51+
Alert.alert("Failed!", e, [
52+
{
53+
text: "Retry",
54+
onPress: () => console.log("failed..."),
55+
},
56+
]);
57+
});
58+
})
59+
.catch((e) => console.log(e));
60+
// console.log(arr);
61+
}

0 commit comments

Comments
 (0)