Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Schedule hide weekend #621

Merged
11 changes: 7 additions & 4 deletions apps/thu-info-app/src/components/schedule/schedule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ interface ScheduleBlockProps {
gridHeight: number;
gridWidth: number;
onPress: () => void;
textColor?: string;
blockColor?: string;
blockMargin?: number;
}

export const ScheduleBlock = (props: ScheduleBlockProps) => {
const themeName = useColorScheme();
const {colors} = themes(themeName);
const { colors } = themes(themeName);

const textColor = props.textColor || "white";

const blockMargin = props.blockMargin || 2;
const blockColor = props.blockColor || colors.themePurple;
Expand Down Expand Up @@ -45,7 +48,7 @@ export const ScheduleBlock = (props: ScheduleBlockProps) => {
height: blockBottomPos - blockTopPos,
backgroundColor: blockColor,
borderRadius: 4,
paddingVertical: 4,
paddingVertical: 6,
paddingHorizontal: 2,
}}
onPress={props.onPress}>
Expand All @@ -58,7 +61,7 @@ export const ScheduleBlock = (props: ScheduleBlockProps) => {
? blockBottomPos - blockTopPos - localeHeight - 5
: blockBottomPos - blockTopPos,
textAlign: "left",
color: "white",
color: textColor,
lineHeight: 18,
fontWeight: "bold",
fontSize: 13,
Expand All @@ -73,7 +76,7 @@ export const ScheduleBlock = (props: ScheduleBlockProps) => {
numberOfLines={3}
style={{
textAlign: "left",
color: "white",
color: textColor,
fontSize: 8,
}}>
{"@" + props.location}
Expand Down
59 changes: 35 additions & 24 deletions apps/thu-info-app/src/ui/schedule/schedule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ export const ScheduleScreen = ({navigation}: {navigation: RootNav}) => {
const hideWeekend = useSelector((s: State) => s.config.hideWeekend);
const unitHeight = exactUnitHeight * (1 + heightMode * 0.05);
const scheduleBodyWidth = windowWidth - 32;
const unitWidth = scheduleBodyWidth / 7;
const unitWidth = scheduleBodyWidth / (hideWeekend ? 5 : 7);

const [openConfig, setOpenConfig] = useState(false);

Expand Down Expand Up @@ -466,7 +466,7 @@ export const ScheduleScreen = ({navigation}: {navigation: RootNav}) => {
position: "absolute",
right: 12,
top: 5 * unitHeight + 40,
fontSize: 12,
fontSize: 10,
color: theme.colors.fontB3,
}}>
{getStr("lunch")}
Expand All @@ -476,7 +476,7 @@ export const ScheduleScreen = ({navigation}: {navigation: RootNav}) => {
position: "absolute",
right: 12,
top: 11 * unitHeight + 40,
fontSize: 12,
fontSize: 10,
color: theme.colors.fontB3,
}}>
{getStr("supper")}
Expand Down Expand Up @@ -549,6 +549,9 @@ export const ScheduleScreen = ({navigation}: {navigation: RootNav}) => {
</View>
<View>
{(item as SliceRenderData[]).map((data) => {
if (hideWeekend && data.slice.dayOfWeek > 5) {
return null;
}
if (data.type === "normal") {
const slice = data.slice;
const val = data.schedule;
Expand All @@ -569,11 +572,12 @@ export const ScheduleScreen = ({navigation}: {navigation: RootNav}) => {
gridWidth={unitWidth}
key={`${val.name}-${num}-${slice.dayOfWeek}-${slice.begin}-${val.location}`}
blockColor={
colorList[
`${colorList[
parseInt(md5(val.name).substr(0, 6), 16) %
colorList.length
]
]}33`
}
textColor={colorList[parseInt(md5(val.name).substr(0, 6), 16) % colorList.length]}
onPress={() => {
navigation.navigate("ScheduleDetail", {
name: val.name,
Expand Down Expand Up @@ -607,11 +611,12 @@ export const ScheduleScreen = ({navigation}: {navigation: RootNav}) => {
gridWidth={unitWidth}
key={`${val.name}-${slice.weekNumber}-${slice.dayOfWeek}-${slice.begin}-${val.location}`}
blockColor={
colorList[
parseInt(md5(val.name).substr(0, 6), 16) %
colorList.length
]
`${colorList[
parseInt(md5(val.name).substr(0, 6), 16) %
colorList.length
]}33`
}
textColor={colorList[parseInt(md5(val.name).substr(0, 6), 16) % colorList.length]}
onPress={() => {
navigation.navigate("ScheduleDetail", {
name: val.name,
Expand Down Expand Up @@ -671,23 +676,29 @@ export const ScheduleScreen = ({navigation}: {navigation: RootNav}) => {
}}
/>
</View>
<View style={{ backgroundColor: theme.colors.contentBackground, flexDirection: "row", justifyContent: "space-between" }}>
<View
style={{
backgroundColor: theme.colors.contentBackground,
flexDirection: "row",
justifyContent: "space-between",
paddingHorizontal: 16,
paddingVertical: 8,
}}>
<Text
style={{
margin: 8,
color: theme.colors.fontB1,
fontSize: 16,
}}>{getStr("hideWeekend")}</Text>
style={{
color: theme.colors.fontB1,
fontSize: 16,
}}>{getStr("hideWeekend")}</Text>
<Switch
thumbColor={theme.colors.contentBackground}
trackColor={{ true: theme.colors.themePurple }}
value={hideWeekend}
onValueChange={(value: boolean) => {
dispatch(configSet({
key: "hideWeekend",
value: value,
}));
}}
thumbColor={theme.colors.contentBackground}
trackColor={{ true: theme.colors.themePurple }}
value={hideWeekend}
onValueChange={(value: boolean) => {
dispatch(configSet({
key: "hideWeekend",
value: value,
}));
}}
/>
</View>
</TouchableOpacity>
Expand Down
Loading