Skip to content

Commit

Permalink
Merge pull request #26 from creeper82/topic-refactor-for-v1.0
Browse files Browse the repository at this point in the history
Refactor for v1.0
  • Loading branch information
creeper82 committed Nov 14, 2023
2 parents cc36829 + bad007e commit 4891471
Show file tree
Hide file tree
Showing 15 changed files with 15 additions and 11 deletions.
4 changes: 2 additions & 2 deletions classes/CLI/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ while (running)
At the start of each loop, `CheckOutOfBoundsPointer` is called. Effectively, it checks whether the currently selected index still exists in the list. If not, then move to the closest optimal index. For example having 4 decks, the user removed deck 4. After calling the function, the ChoiceList will move selection to deck 3.

### Moving forward and backward ###
Then, the `HandleMenu` function is called. You can read more about handling [here](../app/handling/), but generally the handler function checks which key have you pressed, and moves the list in case of the up/down arrow key press. All that happens in the [HandleMenu](../app/handling/Menu.cs) file, as follows:
Then, the `HandleMenu` function is called. You can read more about handling [here](../app/controllers/), but generally the handler function checks which key have you pressed, and moves the list in case of the up/down arrow key press. All that happens in the [HandleMenu](../app/controllers/Menu.cs) file, as follows:

```cs
switch (consoleKey)
Expand All @@ -53,7 +53,7 @@ switch (consoleKey)
These methods already have built-in checking whether the list can be moved, and if the list can't be moved (user wants to go forward on the last index and so on), then the call will be ignored

### Moving to specific item ###
You can also move the list to a specific item. This can be useful if the item has changed its position in the list (let's say - the deck was renamed, and now is at the end of the list due to alphabetical sort) and you want to keep the selection on it. Here's what it looks like - again - in the [HandleMenu](../app/handling/Menu.cs) file:
You can also move the list to a specific item. This can be useful if the item has changed its position in the list (let's say - the deck was renamed, and now is at the end of the list due to alphabetical sort) and you want to keep the selection on it. Here's what it looks like - again - in the [HandleMenu](../app/controllers/Menu.cs) file:
```cs
switch (consoleKey) {
// skipped code
Expand Down
2 changes: 0 additions & 2 deletions classes/app/actions/README.md

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions classes/app/logic/actions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Actions #
These files serve as extension for the [handling](../controllers/) methods. You can read their documentation [here](../controllers/README.md)

In modern architecture, these actions can translate to use-cases
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Handling #
## Controllers #
This folder contains methods of the **Logic** class. Each app screen has a method that handles the user input for that screen and does some logic based on the input. For example - create a new card, or change the sorting method.

It may either only affect the backend, or also modify the screen state directly (for example reveal the current card). For this reason, some methods return the **bool** type and some return a custom **status** type.
It may either only affect the backend, or also modify the interface directly (for example reveal the current card). For this reason, some methods return the **bool** type and some return a custom **status** type.

## Return types ##

Expand Down
File renamed without changes.
File renamed without changes.
12 changes: 7 additions & 5 deletions classes/app/screens/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ App screens are used to display a [CLI screen](../../CLI/screens), handle the us

Typically, the screens have a `running` boolean variable which determines, if the screen should be refreshed after handling the input, or closed (for example when the user presses the Esc key).

A lot more about handling can be found [here](../handling/README.md). Essentially most of the handling methods return true or false (true if the screen should be refreshed, false - aborted). Consider the simple example from [Deck screen](Deck.cs), which shows info about the deck (from there you can start studying, manage the deck and edit that deck's cards)
A lot more about handling can be found [here](../controllers/README.md). Essentially most of the handling methods return true or false (true if the screen should be refreshed, false - aborted). Consider the simple example from [Deck screen](Deck.cs), which shows info about the deck (from there you can start studying, manage the deck and edit that deck's cards)

In MVC architecture, these screens are simply views

```cs
public static void Deck(FlashcardsDatabase database, Deck deck)
Expand All @@ -20,8 +22,8 @@ public static void Deck(FlashcardsDatabase database, Deck deck)

}
```
In case of the [HandleDeck](../handling/Deck.cs) method, the `false` value is returned for example upon deleting the deck (first checking if the user actually accepted the delete dialog by the if statement), or upon pressing Esc key. So when a false value is returned, the loop ends, the screen is closed and goes back to menu.
Here's what it looks like in the [HandleDeck](../handling/Deck.cs) method:
In case of the [HandleDeck](../controllers/Deck.cs) method, the `false` value is returned for example upon deleting the deck (first checking if the user actually accepted the delete dialog by the if statement), or upon pressing Esc key. So when a false value is returned, the loop ends, the screen is closed and goes back to menu.
Here's what it looks like in the [HandleDeck](../controllers/Deck.cs) method:
```cs
switch (consoleKey)
{
Expand All @@ -37,9 +39,9 @@ switch (consoleKey)
```

# Front-end handling #
On the example above, the [HandleDeck](../handling/Deck.cs) method simply returns true/false to signify if the screen should be refreshed. However sometimes it is needed to change a local variable based on the user interaction, for example reveal a card on the study screen upon pressing space.
On the example above, the [HandleDeck](../controllers/Deck.cs) method simply returns true/false to signify if the screen should be refreshed. However sometimes it is needed to change a local variable based on the user interaction, for example reveal a card on the study screen upon pressing space.

That's why a handling function sometimes return custom status types ([read more here](../handling/README.md)). In such case, the handle function does all the back-end job, but the front-end job, such as revealing the card is done in the screen method directly. Consider the [StudySession](StudySession.cs) screen:
That's why a handling function sometimes return custom status types ([read more here](../controllers/README.md)). In such case, the handle function does all the back-end job, but the front-end job, such as revealing the card is done in the screen method directly. Consider the [StudySession](StudySession.cs) screen:
```cs
public static void StudySession(FlashcardsDatabase database, List<Card> cards) {
// skipped code
Expand Down

0 comments on commit 4891471

Please sign in to comment.