Skip to content

Commit b47b978

Browse files
authored
Merge pull request nmfs-ocio#195 from NMFS-RADFish/lesson-5-cleanup
Lesson 5 cleanup
2 parents 8d4a03f + 647e849 commit b47b978

5 files changed

Lines changed: 382 additions & 238 deletions

File tree

docs/learn/lesson-1.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ onClick={() => {
105105
```
106106

107107
**The complete `Button` component with the new `onClick` handler will look like this:**
108-
```jsx title="src/pages/Home.jsx" showLineNumbers=293
108+
```jsx title="src/pages/Home.jsx" showLineNumbers=309
109109
<Button
110110
type="button"
111111
className="bg-primary hover:bg-primary-darker width-full"

docs/learn/lesson-2.mdx

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ These components work together to create accessible, well-structured forms that
4848

4949
**Add the `FormGroup`, `Label`, and `DatePicker` input within the `Form` component:**
5050

51-
```jsx title="src/pages/StartTrip.jsx" showLineNumbers=272
51+
```jsx title="src/pages/StartTrip.jsx" showLineNumbers=287
5252
// diff-add-start
5353
<Form onSubmit={handleSubmit} large>
5454
<FormGroup>
@@ -65,7 +65,7 @@ These components work together to create accessible, well-structured forms that
6565
name="tripDate"
6666
defaultValue={formData.tripDate}
6767
onChange={handleDateChange}
68-
aria-describedby="tripDateHint"
68+
aria-describedby="tripDate-hint"
6969
required
7070
/>
7171
<span id="tripDateHint" className="usa-sr-only">
@@ -82,7 +82,7 @@ Let's look at two key aspects of how React manages state with this form:
8282

8383
1. **Initial State with `defaultValue`**:
8484

85-
```jsx title="src/pages/StartTrip.jsx" showLineNumbers=289
85+
```jsx title="src/pages/StartTrip.jsx" showLineNumbers=303
8686
defaultValue={formData.tripDate}
8787
```
8888

@@ -102,14 +102,14 @@ Let's look at two key aspects of how React manages state with this form:
102102

103103
2. **Updating State with `onChange`**:
104104

105-
```jsx title="src/pages/StartTrip.jsx" showLineNumbers=290
105+
```jsx title="src/pages/StartTrip.jsx" showLineNumbers=304
106106
onChange = { handleDateChange };
107107
```
108108

109109
- The `onChange` attribute is a required prop for controlled inputs. It is called whenever the input's value changes (on every keystroke or selection). Without this handler, React would revert the input to its original value after each change.
110110
- When a user selects a date, the `handleDateChange` function is called
111111

112-
```jsx title="src/pages/StartTrip.jsx" showLineNumbers=149
112+
```jsx title="src/pages/StartTrip.jsx" showLineNumbers=162
113113
const handleDateChange = (value) => {
114114
setFormData((prevData) => ({ ...prevData, tripDate: value || "" }));
115115
};
@@ -148,7 +148,7 @@ import {
148148

149149
Let's add the `TimePicker` input below the `DatePicker` form group:
150150

151-
```jsx title="src/pages/StartTrip.jsx" showLineNumbers=315
151+
```jsx title="src/pages/StartTrip.jsx" showLineNumbers=325
152152
// diff-add-start
153153
<FormGroup>
154154
<Label htmlFor="startTime" className="input-time-label" requiredMarker>
@@ -162,9 +162,9 @@ Let's add the `TimePicker` input below the `DatePicker` form group:
162162
minTime="00:00"
163163
maxTime="23:45"
164164
step={15}
165-
aria-describedby="startTimeHint"
165+
aria-describedby="start-time-hint"
166166
/>
167-
<span id="startTimeHint" className="usa-sr-only">
167+
<span id="start-time-hint" className="usa-sr-only">
168168
Please enter or select the time you started fishing.
169169
</span>
170170
</FormGroup>
@@ -209,7 +209,7 @@ import {
209209

210210
Add the following code below the `TimePicker` form group:
211211

212-
```jsx title="src/pages/StartTrip.jsx" showLineNumbers=352
212+
```jsx title="src/pages/StartTrip.jsx" showLineNumbers=362
213213
// diff-add-start
214214
<FormGroup>
215215
<Label htmlFor="startWeather" requiredMarker>
@@ -220,14 +220,14 @@ Add the following code below the `TimePicker` form group:
220220
name="startWeather"
221221
value={formData.startWeather}
222222
onChange={handleInputChange}
223-
aria-describedby="startWeatherHint"
223+
aria-describedby="start-weather-hint"
224224
>
225225
<option value="">-Select-</option>
226226
<option value="Sunny">Sunny</option>
227227
<option value="Cloudy">Cloudy</option>
228228
<option value="Rainy">Rainy</option>
229229
</Select>
230-
<span id="startWeatherHint" className="usa-sr-only">
230+
<span id="start-weather-hint" className="usa-sr-only">
231231
Please select the weather conditions at the start of your fishing trip.
232232
</span>
233233
</FormGroup>
@@ -240,7 +240,7 @@ Add the following code below the `TimePicker` form group:
240240
- `onChange={handleInputChange}` uses the standard input handler (already present) because the `Select` component behaves like a standard HTML select element in this regard.
241241
- We define the available weather options using standard HTML `<option>` tags within the `Select` component. The first option has an empty `value` to represent the default, unselected state.
242242

243-
The complete **Form** will look like this:
243+
The complete **Form** will look like this:
244244

245245
```jsx title="src/pages/StartTrip.jsx" showLineNumbers=272
246246
// diff-add-start
@@ -259,10 +259,10 @@ The complete **Form** will look like this:
259259
name="tripDate"
260260
defaultValue={formData.tripDate}
261261
onChange={handleDateChange}
262-
aria-describedby="tripDateHint"
262+
aria-describedby="trip-date-hint"
263263
required
264264
/>
265-
<span id="tripDateHint" className="usa-sr-only">
265+
<span id="trip-date-hint" className="usa-sr-only">
266266
Please enter or select the date of your fishing trip.
267267
</span>
268268
</FormGroup>
@@ -278,9 +278,9 @@ The complete **Form** will look like this:
278278
minTime="00:00"
279279
maxTime="23:45"
280280
step={15}
281-
aria-describedby="startTimeHint"
281+
aria-describedby="start-time-hint"
282282
/>
283-
<span id="startTimeHint" className="usa-sr-only">
283+
<span id="start-time-hint" className="usa-sr-only">
284284
Please enter or select the time you started fishing.
285285
</span>
286286
</FormGroup>
@@ -293,18 +293,18 @@ The complete **Form** will look like this:
293293
name="startWeather"
294294
value={formData.startWeather}
295295
onChange={handleInputChange}
296-
aria-describedby="startWeatherHint"
296+
aria-describedby="start-weather-hint"
297297
>
298298
<option value="">-Select-</option>
299299
<option value="Sunny">Sunny</option>
300300
<option value="Cloudy">Cloudy</option>
301301
<option value="Rainy">Rainy</option>
302302
</Select>
303-
<span id="startWeatherHint" className="usa-sr-only">
303+
<span id="start-weather-hint" className="usa-sr-only">
304304
Please select the weather conditions at the start of your fishing trip.
305305
</span>
306306
</FormGroup>
307-
</Form>;
307+
</Form>
308308
// diff-add-end
309309
```
310310

@@ -316,15 +316,15 @@ Before we learn how to save data to storage in the next lesson, let's first see
316316

317317
Open `src/pages/StartTrip.jsx` and locate the `handleSubmit` function. Replace the existing submission logic with the following code that will log the form data to the console:
318318

319-
```jsx title="src/pages/StartTrip.jsx" showLineNumbers=191
319+
```jsx title="src/pages/StartTrip.jsx" showLineNumbers=214
320320
if (Object.keys(newErrors).length === 0) {
321321
//diff-add-start
322322
console.log("Form Data:", {
323323
tripDate: formData.tripDate,
324324
startWeather: formData.startWeather,
325325
startTime: formData.startTime,
326326
status: "in-progress",
327-
step: 2,
327+
step: 2
328328
});
329329
//diff-add-end
330330
}

docs/learn/lesson-3.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ This schema ensures data consistency and provides validation when we create or u
7777

7878
To save data, we first need to access the appropriate RADFish store and collection within our `handleSubmit` function.
7979

80-
```jsx title="src/pages/StartTrip.jsx" showLineNumbers=202
80+
```jsx title="src/pages/StartTrip.jsx" showLineNumbers=203
8181
try {
8282
//diff-add-start
8383
const tripStore = app.stores["trip"];

docs/learn/lesson-4.mdx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ RADFish organizes different types of data into separate **collections**. While o
1212

1313
Open `src/index.jsx` and locate the `collections` section within the trip store. **You'll need to add the Catch collection schema after the Form collection as shown in the highlighted lines below:**
1414

15-
```jsx title="src/index.jsx" showLineNumbers=60
15+
```jsx title="src/index.jsx" showLineNumbers=66
1616
},
1717
},
1818
// diff-add-start
@@ -91,8 +91,7 @@ First, we need to access the RADFish Catch collection within our form submission
9191

9292
Open `src/pages/CatchLog.jsx` and locate the `handleAddCatch` function. Find the comment `// Create record in RADFish/IndexedDB` and replace it with the following code:
9393

94-
```jsx title="src/pages/CatchLog.jsx" showLineNumbers=247
95-
// Create record in RADFish/IndexedDB
94+
```jsx title="src/pages/CatchLog.jsx" showLineNumbers=265
9695
// diff-add-start
9796
await Catch.create(newCatchData);
9897
// diff-add-end
@@ -111,7 +110,7 @@ After successfully saving to IndexedDB, we need to update React's component stat
111110

112111
In the same `handleAddCatch` function, below the `await Catch.create(newCatchData)`, add the following code:
113112

114-
```jsx title="src/pages/CatchLog.jsx" showLineNumbers=250
113+
```jsx title="src/pages/CatchLog.jsx" showLineNumbers=269
115114
// diff-add-start
116115
setCatches(prev => [newCatchData, ...prev]);
117116
// diff-add-end
@@ -133,8 +132,7 @@ This triggers React's re-rendering process, immediately updating the "Recorded C
133132

134133
The complete `handleAddCatch` function also handles form cleanup after successful submission. Here's how the full process works:
135134

136-
```jsx title="src/pages/CatchLog.jsx" showLineNumbers=252
137-
// Reset the form
135+
```jsx title="src/pages/CatchLog.jsx" showLineNumbers=272
138136
setCurrentCatch({ species: "", weight: "", length: "", latitude: "", longitude: "", time: "" });
139137
setCatchTimeKey(prevKey => prevKey + 1); // Reset TimePicker
140138
setSubmitted(false); // Reset submission status

0 commit comments

Comments
 (0)