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

Lesson Cards #258

Merged
merged 29 commits into from
Oct 15, 2023
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e16e6dd
Renamed DrillCardImages folder to CardImages and fixed code references
Gregory711 Oct 14, 2023
eb45d02
Added CardImages specific to lessons
Gregory711 Oct 15, 2023
24307ac
Added bash script to create grayscale versions of CardImages in Learn…
Gregory711 Oct 15, 2023
21bc807
Added comments to grayscale script
Gregory711 Oct 15, 2023
eb98ded
Used grayscale script to create Learned CardImages and updated their …
Gregory711 Oct 15, 2023
b1bca1a
Created script to paste a lock svg in the middle of the grayscaled Ca…
Gregory711 Oct 15, 2023
54135fe
Added lock svg
Gregory711 Oct 15, 2023
7f9eb13
Created locked CardImages using script
Gregory711 Oct 15, 2023
7f4842f
Removed LessonButton from DrillPage.tsx
Gregory711 Oct 15, 2023
504e27a
Replaced LessonButton with Button in LessonPanel
Gregory711 Oct 15, 2023
f04f990
Deleted LessonButton.tsx
Gregory711 Oct 15, 2023
ff7da7e
Replaced Button in LessonPanel with TouchableOpacity and Card
Gregory711 Oct 15, 2023
2ebec5e
Started adding styling to Lesson Cards
Gregory711 Oct 15, 2023
f8b58b3
Created Cards.ts and refactored card width constant to there
Gregory711 Oct 15, 2023
bccef24
Simplified Card padding and refactored const to Cards.ts
Gregory711 Oct 15, 2023
817c35d
Put Lesson Cards in View with Cards.ts styling
Gregory711 Oct 15, 2023
55834b9
Refactored card width and height into Cards.ts consts and used them i…
Gregory711 Oct 15, 2023
e9bc6c0
Updated lessons page to use scroll bar
Gregory711 Oct 15, 2023
2641f0d
Refactored card resizing logic into function in Cards.ts
Gregory711 Oct 15, 2023
89522c5
Passed in width props to LessonPanel and used it to calculate cards p…
Gregory711 Oct 15, 2023
5b02d53
Updated lesson cards to use same resizing strategy as drill cards
Gregory711 Oct 15, 2023
966ab6a
Conditionally rendered regular, learned, or locked lesson card image
Gregory711 Oct 15, 2023
75fd6f9
Changed drillDifficulty type to difficulty and moved to Cards.ts
Gregory711 Oct 15, 2023
e5a7f10
Created getDifficultyColor in Cards and used it in DrillPanel
Gregory711 Oct 15, 2023
4c8157d
Merge branch 'main' into LessonCards
Gregory711 Oct 15, 2023
1c1c9a1
Added difficulty labels to lesson cards
Gregory711 Oct 15, 2023
ed33563
Removed outdated code from LessonPanel.tsx
Gregory711 Oct 15, 2023
177a4ce
Removed outdated react state stuff from DrillPage.tsx
Gregory711 Oct 15, 2023
74c241a
Fixed mobile lesson card resizing
Gregory711 Oct 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added app/Components/Home/CardImages/AMEND_NOTES.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/Components/Home/CardImages/SIMPLIFY_NOTES.png
Binary file added app/Components/Home/CardImages/SUDOKU_101.png
77 changes: 77 additions & 0 deletions app/Components/Home/CardImages/lock.svg
13 changes: 13 additions & 0 deletions app/Components/Home/CardImages/to_grayscale.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

# Get a list of all files in the current directory
files=$(ls)

# Iterate over the list of files
for file in $files; do
# Check if the file is a regular file and if the filename ends in .png
# If both conditions are true, convert the file to grayscale (using ImageMagick)
if [[ -f $file && "$file" =~ \.png$ ]]; then
convert $file -colorspace Gray "Learned/$file"
fi
done
10 changes: 10 additions & 0 deletions app/Components/Home/CardImages/to_locked.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

# Get a list of all files in the Learned directory
files=$(ls Learned)

# Iterate over the list of files
for file in $files; do
# Paste the lock in the center of the image (using ImageMagick)
convert "Learned/$file" -gravity center lock.svg -composite "Locked/$file"
done
45 changes: 45 additions & 0 deletions app/Components/Home/Cards.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
export const CARD_WIDTH: number = 300;
const CARD_HEIGHT: number = 600;
export const CARD_PADDING: number = 20;
export const CARD_IMAGE_WIDTH: number = (CARD_WIDTH * 2) / 3;
export const CARD_IMAGE_HEIGHT: number = CARD_HEIGHT / 2;

/**
* Given window width calculates how many cards should be on each row
* @param width - window width
* @param count - number of cards
* @returns number of cards that can fit on each row
*/
export function calculateCardsPerRow(width: number, count: number): number {
let columnCount: number = Math.floor(width / (CARD_WIDTH + 100));
// Decrease the number of columns to the smallest number that is greater than or equal to the number of rows
while (columnCount - 1 >= Math.ceil(count / (columnCount - 1))) {
columnCount--;
}
return columnCount;
}

export type difficulty =
| "Very Easy"
| "Easy"
| "Intermediate"
| "Hard"
| "Very Hard";

/**
* Given a difficulty returns the corresponding color
*/
export function getDifficultyColor(difficulty: difficulty): string {
switch (difficulty) {
case "Very Easy":
return "#4CBB17";
case "Easy":
return "#7CFC00";
case "Intermediate":
return "#FFFF00";
case "Hard":
return "#FFA500";
default:
return "#FF0000";
}
}
65 changes: 28 additions & 37 deletions app/Components/Home/DrillPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ import React from "react";
import { View, Image, TouchableOpacity, ImageURISource } from "react-native";
import { Card, Text } from "react-native-paper";
import { sudokuStrategyArray } from "sudokuru";
import {
CARD_IMAGE_HEIGHT,
CARD_IMAGE_WIDTH,
CARD_PADDING,
CARD_WIDTH,
calculateCardsPerRow,
difficulty,
getDifficultyColor,
} from "./Cards";

let drillStrategies: sudokuStrategyArray = [
"NAKED_SINGLE",
Expand All @@ -18,25 +27,18 @@ let drillStrategies: sudokuStrategyArray = [
];

let drillImages: ImageURISource[] = [
require("./DrillCardImages/NAKED_SINGLE.png"),
require("./DrillCardImages/NAKED_PAIR.png"),
require("./DrillCardImages/NAKED_TRIPLET.png"),
require("./DrillCardImages/NAKED_QUADRUPLET.png"),
require("./DrillCardImages/HIDDEN_SINGLE.png"),
require("./DrillCardImages/HIDDEN_PAIR.png"),
require("./DrillCardImages/HIDDEN_TRIPLET.png"),
require("./DrillCardImages/HIDDEN_QUADRUPLET.png"),
require("./DrillCardImages/POINTING_PAIR.png"),
require("./DrillCardImages/POINTING_TRIPLET.png"),
require("./CardImages/NAKED_SINGLE.png"),
require("./CardImages/NAKED_PAIR.png"),
require("./CardImages/NAKED_TRIPLET.png"),
require("./CardImages/NAKED_QUADRUPLET.png"),
require("./CardImages/HIDDEN_SINGLE.png"),
require("./CardImages/HIDDEN_PAIR.png"),
require("./CardImages/HIDDEN_TRIPLET.png"),
require("./CardImages/HIDDEN_QUADRUPLET.png"),
require("./CardImages/POINTING_PAIR.png"),
require("./CardImages/POINTING_TRIPLET.png"),
];

type drillDifficulty =
| "Very Easy"
| "Easy"
| "Intermediate"
| "Hard"
| "Very Hard";

/**
* Returns the string converted to a title format i.e. replaces _ with spaces and capitalizes only the first letter of each word
* @param str - the string to convert
Expand All @@ -55,48 +57,37 @@ const DrillPanel = (props: any) => {

let drillButtonArray = [];
let subArray = [];
const CARD_WIDTH: number = 300;
const CARD_HEIGHT: number = 600;
let columnCount: number = Math.floor(props.width / (CARD_WIDTH + 100));
// Decrease the number of columns to the smallest number that is greater than or equal to the number of rows
while (
columnCount - 1 >=
Math.ceil(drillStrategies.length / (columnCount - 1))
) {
columnCount--;
}
let columnCount: number = calculateCardsPerRow(
props.width,
drillStrategies.length
);
for (let i = 0; i < drillStrategies.length; i++) {
let img: ImageURISource = drillImages[i];
let difficulty: drillDifficulty, difficultyColor: string;
let difficulty: difficulty;
switch (drillStrategies[i]) {
case "NAKED_SINGLE":
difficulty = "Very Easy";
difficultyColor = "#4CBB17";
break;
case "NAKED_PAIR":
difficulty = "Easy";
difficultyColor = "#7CFC00";
break;
case "NAKED_TRIPLET":
case "NAKED_QUADRUPLET":
difficulty = "Intermediate";
difficultyColor = "#FFFF00";
break;
case "HIDDEN_SINGLE":
difficulty = "Hard";
difficultyColor = "#FFA500";
break;
default:
difficulty = "Very Hard";
difficultyColor = "#FF0000";
break;
}
let difficultyColor: string = getDifficultyColor(difficulty);
subArray.push(
<View
style={{
width: CARD_WIDTH,
paddingHorizontal: 20,
paddingVertical: 20,
padding: CARD_PADDING,
}}
>
<TouchableOpacity
Expand All @@ -123,8 +114,8 @@ const DrillPanel = (props: any) => {
<Image
source={img}
style={{
width: (CARD_WIDTH * 2) / 3,
height: CARD_HEIGHT / 2,
width: CARD_IMAGE_WIDTH,
height: CARD_IMAGE_HEIGHT,
resizeMode: "contain",
alignSelf: "center",
}}
Expand Down
53 changes: 0 additions & 53 deletions app/Components/Home/LessonButton.tsx

This file was deleted.

Loading