Skip to content

Commit

Permalink
merge: v1.2.4 (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
Damego authored Jan 4, 2024
2 parents ce70960 + d5dc3cc commit 1e35d7d
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 51 deletions.
4 changes: 2 additions & 2 deletions app.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
expo: {
name: 'ЕТИС мобайл' + (IS_DEV ? ' (DEV)' : ''),
slug: 'etis-mobile',
version: '1.2.3',
version: '1.2.4',
owner: 'damego',
orientation: 'portrait',
icon: './assets/icon.png',
Expand All @@ -23,7 +23,7 @@ export default {
supportsTablet: true,
},
android: {
versionCode: 10203000,
versionCode: 10204000,
adaptiveIcon: {
foregroundImage: './assets/adaptive-icon.png',
backgroundColor: '#9B1B2A',
Expand Down
30 changes: 19 additions & 11 deletions src/navigation/StackNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { cache } from '../cache/smartCache';
import Background from '../components/Background';
import { useAppDispatch, useAppSelector } from '../hooks';
import { useAppTheme } from '../hooks/theme';
import { PageType, changeTheme, setInitialPage } from '../redux/reducers/settingsSlice';
import { PageType, changeTheme, setEvents, setInitialPage } from '../redux/reducers/settingsSlice';
import AuthPage from '../screens/auth/Auth';
import Intro from '../screens/intro/Intro';
import MessageHistory from '../screens/messages/MessageHistory';
Expand All @@ -36,9 +36,7 @@ const StackNavigator = () => {
theme: themeType,
events,
} = useAppSelector((state) => state.settings);
// TODO:
// Локальный? стейт для определения, был ли предложен новый год
// Отдельный стейт внутри редакса для снегопада

const theme = useAppTheme();
const dispatch = useAppDispatch();

Expand All @@ -60,29 +58,39 @@ const StackNavigator = () => {
};

const checkHalloweenEvent = async () => {
const $events = { ...events };
const $isHalloween = isHalloween();
const events = await cache.getEvents();
if ($isHalloween && !events.halloween2023?.suggestedTheme) {
events.halloween2023 = {

if ($isHalloween && !$events.halloween2023?.suggestedTheme) {
$events.halloween2023 = {
suggestedTheme: true,
previousTheme: themeType,
};
dispatch(changeTheme(ThemeType.halloween));
cache.placeTheme(ThemeType.halloween);
dispatch(setEvents($events));
cache.placeEvents($events);
}
if (!$isHalloween && themeType === ThemeType.halloween) {
dispatch(changeTheme(events.halloween2023.previousTheme));
cache.placeTheme(events.halloween2023.previousTheme);
if (!$events.halloween2023) {
dispatch(changeTheme(ThemeType.auto));
cache.placeTheme(ThemeType.auto);
} else {
dispatch(changeTheme($events.halloween2023.previousTheme));
cache.placeTheme($events.halloween2023.previousTheme);
}
}
};

const $isNewYear = useMemo(() => isNewYear(), []);
const checkNewYearEvent = () => {
if (!$isNewYear && isNewYearTheme(themeType)) {
let returnTheme: ThemeType;
if (events.newYear2024?.previousTheme && isNewYearTheme(events.newYear2024.previousTheme))

if (!events.newYear2024?.previousTheme || isNewYearTheme(events.newYear2024.previousTheme))
returnTheme = ThemeType.auto;
else returnTheme = events.newYear2024.previousTheme;

dispatch(changeTheme(returnTheme));
cache.placeTheme(returnTheme);
}
Expand Down Expand Up @@ -111,7 +119,7 @@ const StackNavigator = () => {

let component: React.ReactNode;
if (!viewedIntro) component = <Stack.Screen name="Onboarding" component={Intro} />;
else if ($isNewYear && !events.newYear2024?.suggestedTheme)
else if ($isNewYear && !events?.newYear2024?.suggestedTheme)
component = <Stack.Screen name={'NewYearTheme'} component={NewYearThemes} />;
else if (!isSignedIn)
component = (
Expand Down
18 changes: 2 additions & 16 deletions src/screens/announce/AnnounceCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,9 @@ import React from 'react';
import AutoHeightWebView from 'react-native-autoheight-webview';

import Card from '../../components/Card';
import { useGlobalStyles } from '../../hooks';
import { useAppTheme } from '../../hooks/theme';
import { httpClient } from '../../utils';

const getStyles = (textColor) => `
* {
margin: 0;
padding: 0;
list-style: none;
color: ${textColor}
}
a {
text-decoration: none;
color: #427ADE
}
`;
import { getStyles } from '../../utils/webView';

export default function AnnounceCard({ data }) {
const theme = useAppTheme();
Expand All @@ -29,7 +15,7 @@ export default function AnnounceCard({ data }) {
originWhitelist={['*']}
source={{ html: data }}
style={{ flex: 0, width: '100%' }}
customStyle={getStyles(theme.colors.textForBlock)}
customStyle={getStyles(theme.colors.textForBlock, theme.colors.primary)}
injectedJavaScript={
`document.cookie = ${httpClient.getSessionID()}` /* Allows download files */
}
Expand Down
2 changes: 1 addition & 1 deletion src/screens/cathedraTimetable/CathedraTimetable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const CathedraTimetable = ({ route }: ServiceNativeStackScreenProps<'CathedraTim
};

if (isLoading && !data) return <LoadingScreen onRefresh={refresh} />;
if (!data) return <NoData />;
if (!data || !data.timetable || !data.timetable.length) return <NoData />;

const teacherTimetable =
data.timetable.find((timetable) => timetable.teacherName === currentTeacher) ||
Expand Down
4 changes: 1 addition & 3 deletions src/screens/certificate/RequestCertificate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
ToastAndroid,
TouchableOpacity,
View,
useColorScheme,
} from 'react-native';
import Popover, { PopoverPlacement } from 'react-native-popover-view';
import { RadioButtonProps, RadioGroup } from 'react-native-radio-buttons-group';
Expand Down Expand Up @@ -94,7 +93,6 @@ export default function RequestCertificate() {
const [delivery, setDelivery] = useState<string>();
const [keyboardOpen, setKeyboardOpen] = useState<boolean>(false);
const [requestSent, setRequestSent] = useState<boolean>(false);
const schemeColor = useColorScheme() === 'light' ? 'black' : 'white';
const appTheme = useAppTheme();
const navigator = useNavigation();

Expand All @@ -113,7 +111,7 @@ export default function RequestCertificate() {
placement={PopoverPlacement.FLOATING}
from={(_, showPopover) => (
<TouchableOpacity onPress={showPopover}>
<AntDesign name="infocirlceo" size={24} color={schemeColor} />
<AntDesign name="infocirlceo" size={24} color={appTheme.colors.textForBlock} />
</TouchableOpacity>
)}
popoverStyle={[styles.popover, { backgroundColor: appTheme.colors.block }]}
Expand Down
4 changes: 3 additions & 1 deletion src/screens/messages/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { StyleSheet, View } from 'react-native';
import CardHeaderOut from '../../components/CardHeaderOut';
import FileTextLink from '../../components/FileTextLink';
import Text from '../../components/Text';
import { useAppTheme } from '../../hooks/theme';
import { IMessage, IMessageFile, MessageType } from '../../models/messages';
import { parseDate } from '../../parser/utils';
import { fontSize } from '../../utils/texts';
Expand Down Expand Up @@ -39,6 +40,7 @@ function Message({ message }: { message: IMessage }) {
const time = parseDate(message.time);
const formattedTime = time.format('DD.MM.YYYY HH:mm');
const hasFiles = message.files && message.files.length !== 0;
const theme = useAppTheme();

let cardTopText: string;
if ([MessageType.message, MessageType.teacherReply].includes(message.type))
Expand All @@ -47,7 +49,7 @@ function Message({ message }: { message: IMessage }) {

return (
<CardHeaderOut topText={cardTopText}>
<Text colorVariant={'block'} selectable selectionColor={'#ade1f5'}>
<Text colorVariant={'block'} selectable selectionColor={theme.colors.primary}>
{message.content}
</Text>
{hasFiles ? <AttachedFiles files={message.files} /> : ''}
Expand Down
2 changes: 1 addition & 1 deletion src/screens/messages/MessageInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ const MessageInput = ({
value={value}
placeholder="Сообщение"
multiline
selectionColor="#C62E3E"
selectionColor={globalStyles.primaryFontColor.color}
placeholderTextColor={theme.colors.inputPlaceholder}
editable={!disabled}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/screens/sessionQuestionnaire/AdditionalComment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function AdditionalComment({ onTextChange }: { onTextChange(text:
placeholderTextColor={globalStyles.inputPlaceholder.color}
inputMode="text"
keyboardType="default"
selectionColor="#C62E3E"
selectionColor={globalStyles.primaryFontColor.color}
autoCapitalize={'sentences'}
multiline
maxLength={4000}
Expand Down
5 changes: 4 additions & 1 deletion src/screens/settings/ChangeNewYearTheme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import Card from '../../components/Card';
import ClickableText from '../../components/ClickableText';
import { useAppDispatch, useAppSelector } from '../../hooks';
import { setEvents } from '../../redux/reducers/settingsSlice';
import { ThemeType, isNewYearTheme } from '../../styles/themes';
import { fontSize } from '../../utils/texts';

const ChangeNewYearTheme = () => {
const dispatch = useAppDispatch();
const { events } = useAppSelector((state) => state.settings);
const { events, theme } = useAppSelector((state) => state.settings);

const clearEvent = () => {
const $events = { ...events };
Expand All @@ -21,6 +22,8 @@ const ChangeNewYearTheme = () => {
cache.placeEvents($events);
};

if (!isNewYearTheme(theme)) return;

return (
<Card>
<ClickableText
Expand Down
10 changes: 3 additions & 7 deletions src/screens/timeTable/Pair.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,13 @@ const AnnouncePopover = ({ data }: { data: string }) => {
>
<AutoHeightWebView
source={{ html: data }}
customStyle={getStyles(theme.colors.textForBlock)}
customStyle={getStyles(theme.colors.textForBlock, theme.colors.primary)}
/>
</Popover>
);
};

const Lesson = ({ data, teachersData }: { data: ILesson; teachersData: TeacherType }) => {
const globalStyles = useGlobalStyles();

const location =
data.audience && data.building && data.floor
? `ауд. ${data.audience} (${data.building} корпус, ${data.floor} этаж)`
Expand Down Expand Up @@ -95,10 +93,8 @@ const Lesson = ({ data, teachersData }: { data: ILesson; teachersData: TeacherTy
onPress={() => {
Linking.openURL(data.distancePlatform.url);
}}
textStyle={[
globalStyles.textColor,
{ textDecorationLine: 'underline', fontWeight: '500' },
]}
textStyle={{ textDecorationLine: 'underline', fontWeight: '500' }}
colorVariant={'block'}
/>
) : audience ? (
<Text colorVariant={'block'}>{audience}</Text>
Expand Down
2 changes: 1 addition & 1 deletion src/styles/themes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export const BlueNewYearTheme: ITheme = {
backgroundGradient: ['#131723', '#131723'],
primary: '#409ad4',
secondary: '#c42e21',
border: '#181f32',
border: '#2e3c5f',
text: '#FEFEFE',
textForPrimary: '#FEFEFE',
textForSecondary: '#FEFEFE',
Expand Down
17 changes: 12 additions & 5 deletions src/utils/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@ export interface Events {
newYear2024?: EventData;
}

const isInDateRange = (startDate: Date, endDate: Date) => {
const isInDateRange = (startDate: Date, endDate: Date, checkCondition: 'and' | 'or' = 'and') => {
const currentDateTime = Date.now();
const stateDateTime = startDate.getTime();
const endDateTime = endDate.getTime();

return currentDateTime > stateDateTime && currentDateTime < endDateTime;
if (checkCondition === 'and')
return currentDateTime > stateDateTime && currentDateTime < endDateTime;

// Применимо исключительно к промежутку, который начинается в одном году, а заканчивается в следующем
if (checkCondition === 'or')
return currentDateTime > stateDateTime || currentDateTime < endDateTime;
};

export const isHalloween = () => {
Expand All @@ -40,9 +45,11 @@ export const halloweenEmptyDayResponses = [
export const isNewYear = () => {
const year = new Date().getFullYear();
const startDate = new Date(year, 11, 9);
const endDate = new Date(year + 1, 0, 15);

return isInDateRange(startDate, endDate);
const endDate = new Date(year, 0, 15);
// Новогоднее событие начинается в одном году,
// а заканчивается в следующем,
// поэтому проверяем только месяц и день, а значение года окончания события является текущим
return isInDateRange(startDate, endDate, 'or');
};

export const newYearEmptyDayResponse = [
Expand Down
6 changes: 5 additions & 1 deletion src/utils/webView.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const getStyles = (textColor: string) => `
export const getStyles = (textColor: string, selectionColor: string) => `
* {
margin: 0;
padding: 0;
Expand All @@ -11,4 +11,8 @@ a {
color: #427ADE;
overflow-wrap: break-word;
}
::selection {
background: ${selectionColor}
}
`;

0 comments on commit 1e35d7d

Please sign in to comment.