Skip to content

Commit

Permalink
fix(app): fix some minor bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
agjini committed Jul 26, 2024
1 parent be91699 commit ccda251
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 30 deletions.
1 change: 0 additions & 1 deletion app/src/components/base/AppExpandingTextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export const AppExpandingTextInput = ({ style, backgroundStyle, ...props }: AppT
]}>
<AppTextInput
{...props}
multiline={true}
onContentSizeChange={event => {
setContentHeight(event.nativeEvent.contentSize.height);
}}
Expand Down
45 changes: 16 additions & 29 deletions app/src/screens/communities/CommunitiesChatScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ export const CommunitiesChatScreen = () => {
onPress={() => setTripModalVisible(true)}
name={"plus-outline"}
style={{ padding: 12 }}
backgroundStyle={{ borderRadius: 24, backgroundColor: AppColors.primaryColor }}
backgroundStyle={{ borderRadius: 24, backgroundColor: AppColors.primaryColor, maxHeight: 58 }}
/>
)}

Expand All @@ -398,20 +398,15 @@ export const CommunitiesChatScreen = () => {
tripModalVisible={tripModalVisible}
setTripModalVisible={setTripModalVisible}
launchTrip={launchTrip}
initialDate={startDate}
startDate={startDate}
/>
)}
</KeyboardAvoidingView>
</View>
);
};

type StartTime = {
hour: number;
minute: number;
};

const getNextAvailableDay = (weekdays: string, start: StartTime): string => {
const getNextAvailableDay = (weekdays: string, start: Date): DayOfWeekFlag => {
if (weekdays.length !== 7) {
throw new Error("La chaîne weekdays doit contenir 7 caractères.");
}
Expand All @@ -437,7 +432,7 @@ const getNextAvailableDay = (weekdays: string, start: StartTime): string => {
let nextDayIndex = findNextDay(currentDay);

// If the current day is available but the current time is before the start time
if (weekdays[currentDay] === "1" && (currentHour < start.hour || (currentHour === start.hour && currentMinute < start.minute))) {
if (weekdays[currentDay] === "1" && (currentHour < start.getHours() || (currentHour === start.getHours() && currentMinute < start.getMinutes()))) {
nextDayIndex = currentDay;
}

Expand All @@ -448,35 +443,27 @@ const getNextAvailableDay = (weekdays: string, start: StartTime): string => {
const result = "0000000".split("");
result[nextDayIndex] = "1";

return result.join("");
};

const createDateFromStart = (start: StartTime): Date => {
const now = new Date();
return new Date(now.getFullYear(), now.getMonth(), now.getDate(), start.hour, start.minute, 0, 0);
return result.join("") as DayOfWeekFlag;
};

const LaunchTripModal = ({
tripModalVisible,
setTripModalVisible,
launchTrip,
lianeRequest,
initialDate
startDate
}: {
initialDate: Date;
startDate: Date;
lianeRequest: ResolvedLianeRequest;
tripModalVisible: boolean;
setTripModalVisible: (v: boolean) => void;
launchTrip: (d: [Date, Date | undefined], from: string | undefined, to: string | undefined) => void;
}) => {
const defaultTimeDate = createDateFromStart((lianeRequest as any).when?.start) ?? initialDate;

const [launchTripStep, setLaunchTripStep] = useState(0);
const [selectedTime, setSelectedTime] = useState<[Date, Date | undefined]>([new Date(), undefined]);
// @ts-ignore
const [selectedDay, setSelectedDay] = useState<DayOfWeekFlag>(getNextAvailableDay(lianeRequest.weekDays, (lianeRequest as any).when?.start));
const [from, SetFrom] = useState<RallyingPoint>(lianeRequest.wayPoints[0]);
const [to, SetTo] = useState<RallyingPoint>(lianeRequest.wayPoints[lianeRequest.wayPoints.length - 1]);
const [selectedDay, setSelectedDay] = useState<DayOfWeekFlag>(getNextAvailableDay(lianeRequest.weekDays, startDate));
const [from, setFrom] = useState<RallyingPoint>(lianeRequest.wayPoints[0]);
const [to, setTo] = useState<RallyingPoint>(lianeRequest.wayPoints[lianeRequest.wayPoints.length - 1]);

const launch = () => {
const todayIndex = (selectedTime[0].getDay() + 6) % 7;
Expand All @@ -497,16 +484,16 @@ const LaunchTripModal = ({
launchTripStep === 2
? selectedTime[1]
? addSeconds(selectedTime[1], returnDay * 3600 * 24)
: addSeconds(defaultTimeDate, returnDay * 3600 * 24)
: addSeconds(startDate, returnDay * 3600 * 24)
: undefined;

launchTrip([departureTime, returnTime], from.id, to.id);
};

const switchDestination = () => {
const ToTemp = to;
SetTo(from);
SetFrom(ToTemp);
setTo(from);
setFrom(ToTemp);
};

return (
Expand Down Expand Up @@ -547,7 +534,7 @@ const LaunchTripModal = ({
</View>
<AppText style={styles.modalText}>Départ à :</AppText>
<Center>
<TimeWheelPicker date={defaultTimeDate} minuteStep={5} onChange={d => setSelectedTime([d, undefined])} />
<TimeWheelPicker date={startDate} minuteStep={5} onChange={d => setSelectedTime([d, undefined])} />
</Center>
<Row style={{ justifyContent: "flex-end" }}>
<AppPressableIcon name={"checkmark-outline"} onPress={launch} />
Expand All @@ -573,13 +560,13 @@ const LaunchTripModal = ({
<Column>
<AppText style={styles.modalText}>Départ à :</AppText>
<Center>
<TimeWheelPicker date={defaultTimeDate} minuteStep={5} onChange={d => setSelectedTime(v => [d, v[1]])} />
<TimeWheelPicker date={startDate} minuteStep={5} onChange={d => setSelectedTime(v => [d, v[1]])} />
</Center>
</Column>
<Column>
<AppText style={styles.modalText}>Retour à :</AppText>
<Center>
<TimeWheelPicker date={defaultTimeDate} minuteStep={5} onChange={d => setSelectedTime(v => [v[0], d])} />
<TimeWheelPicker date={startDate} minuteStep={5} onChange={d => setSelectedTime(v => [v[0], d])} />
</Center>
</Column>
</Row>
Expand Down

0 comments on commit ccda251

Please sign in to comment.