Compare commits

..

No commits in common. "3f75396bc405fe9eaf2757d05676c457d77f7567" and "39b264ea53d68389610b434cf21f417b5284304a" have entirely different histories.

4 changed files with 62 additions and 75 deletions

View File

@ -37,16 +37,19 @@ export default function Timetable({ addTimetableEntry, removeTimetableEntry, tim
/> />
)} )}
</Stack.Screen> </Stack.Screen>
<Stack.Screen name="New Entry"> {days.map((day, idx) => (
{(props) => ( <Stack.Screen name={`New Entry ${day}`} key={idx}>
<AddEntry {(props) => (
{...props} <AddEntry
subjects={subjects} {...props}
days={days} subjects={subjects}
addTimetableEntry={addTimetableEntry} day={idx}
/> days={days}
)} addTimetableEntry={addTimetableEntry}
</Stack.Screen> />
)}
</Stack.Screen>
))}
</Stack.Navigator></Portal.Host> </Stack.Navigator></Portal.Host>
); );
} }

View File

@ -1,24 +1,20 @@
import React, { useState } from "react"; import React, { useState } from "react";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import { import {
IconButton,
Card, Card,
FAB, FAB,
IconButton,
List, List,
Menu, Menu,
Portal, Portal,
Snackbar, Snackbar,
TextInput, TextInput,
ToggleButton,
} from "react-native-paper"; } from "react-native-paper";
import { import {StyleSheet} from "react-native";
StyleSheet,
View
} from "react-native";
import DateTimePicker from "@react-native-community/datetimepicker"; import DateTimePicker from "@react-native-community/datetimepicker";
import { format } from "date-fns"; import { format } from "date-fns";
function AddEntry({addTimetableEntry, days, subjects, navigation }) { function AddEntry({addTimetableEntry, days, day, subjects, navigation }) {
const [ subject, setSubject ] = useState({ id: null, name: null }); const [ subject, setSubject ] = useState({ id: null, name: null });
const [ showSubjectMenu, setShowSubjectMenu ] = useState(false); const [ showSubjectMenu, setShowSubjectMenu ] = useState(false);
const [ showTimePicker, setShowTimePicker ] = useState(false); const [ showTimePicker, setShowTimePicker ] = useState(false);
@ -28,7 +24,6 @@ function AddEntry({addTimetableEntry, days, subjects, navigation }) {
const [ end, setEnd ] = useState(null); const [ end, setEnd ] = useState(null);
const [ count, setCount ] = useState(0); const [ count, setCount ] = useState(0);
const [ snackbar, setSnackbar ] = useState({ visible: false, message: "" }); const [ snackbar, setSnackbar ] = useState({ visible: false, message: "" });
const [ dayStates, setDayStates ] = useState([ true, false, false, false, false, false, false ]);
function parseCount(text) { function parseCount(text) {
const num = parseInt(text); const num = parseInt(text);
if (isNaN(num)) if (isNaN(num))
@ -61,8 +56,6 @@ function AddEntry({addTimetableEntry, days, subjects, navigation }) {
message = "Missing end time."; message = "Missing end time.";
else if (count === 0) else if (count === 0)
message = "Missing count."; message = "Missing count.";
if (! dayStates.filter(i => i).length)
message = "No day selected.";
if (message !== "") { if (message !== "") {
setSnackbar({visible: true, message: message}); setSnackbar({visible: true, message: message});
@ -70,16 +63,11 @@ function AddEntry({addTimetableEntry, days, subjects, navigation }) {
return; return;
} }
addTimetableEntry(day, {
dayStates.forEach((i, idx) => { sub_id: subject.id,
if (i) { count,
addTimetableEntry(idx, { start,
sub_id: subject.id, end
count,
start,
end
});
}
}); });
navigation.pop(); navigation.pop();
} }
@ -88,7 +76,7 @@ function AddEntry({addTimetableEntry, days, subjects, navigation }) {
return (<> return (<>
<IconButton icon="arrow-left" onPress={() => navigation.pop()}/> <IconButton icon="arrow-left" onPress={() => navigation.pop()}/>
<Card style={style.card}> <Card style={style.card}>
<Card.Title title="Add Class" /> <Card.Title title={`Add Class on ${days[day]}`} />
<Card.Content> <Card.Content>
<List.Section> <List.Section>
<Menu <Menu
@ -139,26 +127,6 @@ function AddEntry({addTimetableEntry, days, subjects, navigation }) {
value={count === 0 ? "" : count.toString()} value={count === 0 ? "" : count.toString()}
onChangeText={parseCount} onChangeText={parseCount}
/> />
<View
style={style.daysContainer}
>
{dayStates.map( (i, idx) => (
<ToggleButton
key={idx}
icon={`alpha-${days[idx][0].toLowerCase()}`}
status={i ? "checked": "unchecked"}
onPress={
() =>
setDayStates([
...dayStates.slice(0, idx),
!i,
...dayStates.slice(idx + 1)
])
}
/>
)
)}
</View>
</List.Section> </List.Section>
</Card.Content> </Card.Content>
</Card> </Card>
@ -203,8 +171,9 @@ function AddEntry({addTimetableEntry, days, subjects, navigation }) {
AddEntry.propTypes = { AddEntry.propTypes = {
addTimetableEntry: PropTypes.func, addTimetableEntry: PropTypes.func,
subjects: PropTypes.array, subjects: PropTypes.array,
days: PropTypes.array,
navigation: PropTypes.object, navigation: PropTypes.object,
days: PropTypes.array,
day: PropTypes.number,
}; };
const style = StyleSheet.create({ const style = StyleSheet.create({
@ -221,11 +190,6 @@ const style = StyleSheet.create({
flexDirection: "row", flexDirection: "row",
justifyContent: "space-between" justifyContent: "space-between"
}, },
daysContainer: {
flexDirection: "row",
justifyContent: "space-evenly",
marginTop: 10
},
}); });
export default AddEntry; export default AddEntry;

View File

@ -3,11 +3,12 @@ import PropTypes from "prop-types";
import { import {
Button, Button,
IconButton,
Card, Card,
DataTable, DataTable,
Dialog, Dialog,
FAB,
Portal, Portal,
withTheme,
} from "react-native-paper"; } from "react-native-paper";
import { import {
@ -21,14 +22,14 @@ function sortTimes(t1, t2) {
return 1; return 1;
if (t1.getHours() < t2.getHours()) if (t1.getHours() < t2.getHours())
return -1; return -1;
if (t1.getMinutes() > t2.getMinutes()) if (t1.getMinute() > t2.getMinute())
return 1; return 1;
if (t1.getMinutes() < t2.getMinutes()) if (t1.getMinute() < t2.getMinute())
return -1; return -1;
return 0; return 0;
} }
function HomeScreen({ days, navigation, removeTimetableEntry, subjects, timetable }) { function HomeScreen({ days, navigation, removeTimetableEntry, subjects, theme, timetable }) {
const [ dialog, setDialog ] = useState({ show: false, id: null }); const [ dialog, setDialog ] = useState({ show: false, id: null });
return (<Portal.Host><ScrollView> return (<Portal.Host><ScrollView>
{timetable.map((day, dayIdx) => ( {timetable.map((day, dayIdx) => (
@ -98,6 +99,13 @@ function HomeScreen({ days, navigation, removeTimetableEntry, subjects, timetabl
})} })}
</DataTable> </DataTable>
</Card.Content> </Card.Content>
<Card.Actions style={{justifyContent: "flex-end"}}>
<IconButton
onPress={() => navigation.navigate(`New Entry ${days[dayIdx]}`)}
icon="plus"
color={theme.colors.primary}
/>
</Card.Actions>
</Card> </Card>
))} ))}
<Portal> <Portal>
@ -117,17 +125,6 @@ function HomeScreen({ days, navigation, removeTimetableEntry, subjects, timetabl
</Button> </Button>
</Dialog.Actions> </Dialog.Actions>
</Dialog> </Dialog>
<FAB
loarge
icon="plus"
onPress={() => navigation.navigate("New Entry")}
style={{
position: "absolute",
margin: 16,
right: 0,
bottom: 0,
}}
/>
</Portal> </Portal>
</ScrollView></Portal.Host>); </ScrollView></Portal.Host>);
} }
@ -137,6 +134,7 @@ HomeScreen.propTypes = {
subjects: PropTypes.array, subjects: PropTypes.array,
navigation: PropTypes.object, navigation: PropTypes.object,
days: PropTypes.array, days: PropTypes.array,
theme: PropTypes.object,
removeTimetableEntry: PropTypes.func, removeTimetableEntry: PropTypes.func,
}; };
@ -156,4 +154,4 @@ const style = StyleSheet.create({
}, },
}); });
export default HomeScreen; export default withTheme(HomeScreen);

View File

@ -1,13 +1,13 @@
import { DefaultTheme, DarkTheme } from "react-native-paper"; import { DefaultTheme, DarkTheme } from "react-native-paper";
export default [ export default [
{ {
"name": "Dark: Pink and Blue", "name": "Dark: Pink and Gray",
"theme": { "theme": {
...DarkTheme, ...DarkTheme,
mode: "exact", mode: "exact",
colors: { colors: {
primary: "#ff1744", primary: "#ff1744",
accent: "#3949ab", accent: "#e0e0e0",
backdrop: "rgba(0, 0, 0, 0.5)", backdrop: "rgba(0, 0, 0, 0.5)",
background: "#000000", background: "#000000",
disabled: "rgba(255, 255, 255, 0.38)", disabled: "rgba(255, 255, 255, 0.38)",
@ -63,6 +63,17 @@ export default [
} }
} }
}, },
{
"name": "Absolute Dark: Pink and Gray",
"theme": {
...DarkTheme,
colors: {
...DarkTheme.colors,
primary: "#ff1744",
accent: "#e0e0e0",
}
}
},
{ {
"name": "Absolute Dark: Purple and Gray", "name": "Absolute Dark: Purple and Gray",
"theme": DarkTheme "theme": DarkTheme
@ -90,6 +101,17 @@ export default [
} }
} }
}, },
{
"name": "Light: Pastel Colors 2",
"theme": {
...DefaultTheme,
colors: {
...DefaultTheme.colors,
primary: "#ffcccb",
accent: "#fce4ec",
}
}
},
{ {
"name": "Light: Purple and Green", "name": "Light: Purple and Green",
"theme": DefaultTheme "theme": DefaultTheme