@dytsou/intern-corner-scheduler 1.2.8 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/App.jsx CHANGED
@@ -3,51 +3,147 @@ import ScheduleForm from './components/ScheduleForm';
3
3
  import ResultsDisplay from './components/ResultsDisplay';
4
4
  import ErrorMessage from './components/ErrorMessage';
5
5
  import Header from './components/Header';
6
+ import GenerationLoadingScreen from './components/GenerationLoadingScreen';
6
7
  import Footer from './components/Footer';
8
+ import {
9
+ cancelScheduleSolve,
10
+ solveScheduleLocally,
11
+ } from './services/schedulerClient';
7
12
  import './App.css';
8
13
 
9
14
  function App() {
10
15
  const [schedule, setSchedule] = useState(null);
11
16
  const [error, setError] = useState(null);
12
17
  const [loading, setLoading] = useState(false);
18
+ const [cancelling, setCancelling] = useState(false);
19
+ const [statusMessage, setStatusMessage] = useState('');
13
20
 
14
21
  const handleScheduleSubmit = async (formData) => {
15
22
  setError(null);
16
23
  setLoading(true);
24
+ setStatusMessage('Generating schedule in your browser…');
17
25
 
18
26
  try {
19
- const { generateSchedule } = await import('./services/api');
20
- const data = await generateSchedule(formData);
21
- setSchedule(data);
27
+ const result = await solveScheduleLocally(formData, {
28
+ onStatus(stage) {
29
+ if (stage === 'solving') {
30
+ setStatusMessage('Solving in a browser worker…');
31
+ }
32
+ },
33
+ });
34
+ const solverStatus = String(result.solver_status).toUpperCase();
35
+
36
+ if (solverStatus === 'OPTIMAL' || solverStatus === 'FEASIBLE') {
37
+ setSchedule(result);
38
+ setStatusMessage(
39
+ `Schedule generated locally. Solver status: ${solverStatus}.`
40
+ );
41
+ } else if (solverStatus === 'INFEASIBLE') {
42
+ setStatusMessage('');
43
+ setError(
44
+ 'No schedule satisfies these constraints. Try changing the pair restrictions and submit again.'
45
+ );
46
+ } else if (solverStatus === 'UNKNOWN') {
47
+ setStatusMessage('');
48
+ setError(
49
+ 'The browser solver reached the time limit before finding a schedule. Increase the time limit or simplify the inputs and try again.'
50
+ );
51
+ } else if (solverStatus === 'MODEL_INVALID') {
52
+ setStatusMessage('');
53
+ setError(
54
+ 'The browser solver rejected this schedule model. Check the inputs and try again.'
55
+ );
56
+ } else {
57
+ setStatusMessage('');
58
+ setError(
59
+ `The browser solver stopped with status ${solverStatus || 'unknown'}. You can review the inputs and try again.`
60
+ );
61
+ }
22
62
  } catch (err) {
63
+ if (err?.name === 'AbortError') {
64
+ setStatusMessage(
65
+ 'Schedule generation was cancelled. The browser worker has stopped.'
66
+ );
67
+ return;
68
+ }
69
+ const detail = err instanceof Error ? err.message : String(err);
70
+ setStatusMessage('');
23
71
  setError(
24
- `Failed to generate schedule: ${err.message}. Make sure the backend is running and accessible.`
72
+ `The browser solver could not start or finish. ${detail || 'Please try again.'}`
25
73
  );
26
74
  } finally {
27
75
  setLoading(false);
28
76
  }
29
77
  };
30
78
 
79
+ const handleCancelSchedule = async () => {
80
+ if (cancelling) return;
81
+
82
+ setCancelling(true);
83
+ setStatusMessage('Stopping the browser worker…');
84
+ setError(null);
85
+ try {
86
+ await cancelScheduleSolve();
87
+ } catch (err) {
88
+ const detail = err instanceof Error ? err.message : String(err);
89
+ setStatusMessage('The browser worker could not be stopped.');
90
+ setError(detail || 'Try again after the current solve finishes.');
91
+ } finally {
92
+ setCancelling(false);
93
+ }
94
+ };
95
+
31
96
  const handleReset = () => {
32
97
  setSchedule(null);
33
98
  setError(null);
99
+ setStatusMessage('');
34
100
  };
35
101
 
36
102
  return (
37
- <div className="container">
38
- <Header />
39
- <div className="main-content">
40
- {!schedule ? (
41
- <ScheduleForm onSubmit={handleScheduleSubmit} loading={loading} />
42
- ) : (
43
- <ResultsDisplay schedule={schedule} onReset={handleReset} />
44
- )}
45
- {error && (
46
- <ErrorMessage message={error} onDismiss={() => setError(null)} />
47
- )}
103
+ <>
104
+ <div
105
+ className="container"
106
+ aria-hidden={loading || undefined}
107
+ inert={loading || undefined}
108
+ >
109
+ <Header />
110
+ <div className="main-content">
111
+ {statusMessage && (
112
+ <p
113
+ className="solver-status"
114
+ role="status"
115
+ aria-live="polite"
116
+ aria-atomic="true"
117
+ >
118
+ {statusMessage}
119
+ </p>
120
+ )}
121
+ {!schedule ? (
122
+ <ScheduleForm
123
+ onSubmit={handleScheduleSubmit}
124
+ onCancel={handleCancelSchedule}
125
+ loading={loading}
126
+ cancelling={cancelling}
127
+ />
128
+ ) : (
129
+ <ResultsDisplay schedule={schedule} onReset={handleReset} />
130
+ )}
131
+ {error && (
132
+ <ErrorMessage message={error} onDismiss={() => setError(null)} />
133
+ )}
134
+ </div>
135
+ <Footer />
48
136
  </div>
49
- <Footer />
50
- </div>
137
+ {loading && (
138
+ <GenerationLoadingScreen
139
+ statusMessage={statusMessage}
140
+ cancelling={cancelling}
141
+ error={error}
142
+ onCancel={handleCancelSchedule}
143
+ onDismissError={() => setError(null)}
144
+ />
145
+ )}
146
+ </>
51
147
  );
52
148
  }
53
149
 
@@ -2,10 +2,11 @@ function ErrorMessage({ message, onDismiss }) {
2
2
  if (!message) return null;
3
3
 
4
4
  return (
5
- <div className="error-message" style={{ display: 'block' }}>
6
- {message}
5
+ <div className="error-message" role="alert" aria-atomic="true">
6
+ <span>{message}</span>
7
7
  {onDismiss && (
8
8
  <button
9
+ type="button"
9
10
  onClick={onDismiss}
10
11
  className="error-dismiss"
11
12
  aria-label="Dismiss error"
@@ -0,0 +1,48 @@
1
+ import ErrorMessage from './ErrorMessage';
2
+ import LoadingSpinner from './LoadingSpinner';
3
+
4
+ function GenerationLoadingScreen({
5
+ statusMessage,
6
+ cancelling,
7
+ error,
8
+ onCancel,
9
+ onDismissError,
10
+ }) {
11
+ return (
12
+ <div className="generation-screen">
13
+ <dialog
14
+ open
15
+ className="generation-loader"
16
+ aria-modal="true"
17
+ aria-labelledby="generation-title"
18
+ >
19
+ <h1 id="generation-title" className="visually-hidden">
20
+ Generating schedule
21
+ </h1>
22
+ <div
23
+ className="generation-spinner"
24
+ role="status"
25
+ aria-live="polite"
26
+ aria-atomic="true"
27
+ >
28
+ <LoadingSpinner />
29
+ <span className="visually-hidden">
30
+ {statusMessage || 'Finding a good mix for every round…'}
31
+ </span>
32
+ </div>
33
+ <ErrorMessage message={error} onDismiss={onDismissError} />
34
+ <button
35
+ type="button"
36
+ className="btn-secondary generation-cancel"
37
+ onClick={onCancel}
38
+ disabled={cancelling}
39
+ autoFocus
40
+ >
41
+ {cancelling ? 'Stopping…' : 'Cancel generation'}
42
+ </button>
43
+ </dialog>
44
+ </div>
45
+ );
46
+ }
47
+
48
+ export default GenerationLoadingScreen;
@@ -1,10 +1,28 @@
1
+ import LoadingSpinner from './LoadingSpinner';
2
+
1
3
  function Header() {
2
4
  return (
3
- <header>
4
- <h1>Round-Table Scheduler</h1>
5
- <p className="subtitle">
6
- Generate optimal seating arrangements with constraints
7
- </p>
5
+ <header className="site-header">
6
+ <div className="hero-panel">
7
+ <div className="hero-copy">
8
+ <p className="eyebrow">
9
+ <span className="eyebrow-dot" aria-hidden="true" />A BETTER MIX,
10
+ EVERY ROUND
11
+ </p>
12
+ <h1>
13
+ Round-Table <span>Scheduler</span>
14
+ </h1>
15
+ <p className="subtitle">
16
+ Plan your tables in a couple of minutes. We’ll find a good mix for
17
+ every round.
18
+ </p>
19
+ </div>
20
+
21
+ <div className="hero-loading" aria-hidden="true">
22
+ <LoadingSpinner />
23
+ <span className="hero-loading-label">MIXING TABLES</span>
24
+ </div>
25
+ </div>
8
26
  </header>
9
27
  );
10
28
  }
@@ -0,0 +1,11 @@
1
+ function LoadingSpinner() {
2
+ return (
3
+ <div className="hero-spinner" aria-hidden="true">
4
+ <span />
5
+ <span />
6
+ <span />
7
+ </div>
8
+ );
9
+ }
10
+
11
+ export default LoadingSpinner;
@@ -1,4 +1,4 @@
1
- function PairInput({ pair, onChange, onRemove }) {
1
+ function PairInput({ pair, pairLabel, helpId, onChange, onRemove }) {
2
2
  const handleUChange = (e) => {
3
3
  const value = e.target.value;
4
4
  onChange('u', value === '' ? '' : parseInt(value) || '');
@@ -10,13 +10,19 @@ function PairInput({ pair, onChange, onRemove }) {
10
10
  };
11
11
 
12
12
  return (
13
- <div className="pair-item">
14
- <span className="pair-label">Pair:</span>
13
+ <fieldset className="pair-item">
14
+ <legend className="visually-hidden">{pairLabel}</legend>
15
+ <span className="pair-label" aria-hidden="true">
16
+ PAIR
17
+ </span>
15
18
  <input
16
19
  type="number"
17
20
  className="pair-u"
18
21
  placeholder="Participant 1"
22
+ aria-label="Participant 1"
19
23
  min="1"
24
+ inputMode="numeric"
25
+ aria-describedby={helpId}
20
26
  value={pair.u === '' || pair.u === undefined ? '' : pair.u}
21
27
  onChange={handleUChange}
22
28
  />
@@ -25,14 +31,22 @@ function PairInput({ pair, onChange, onRemove }) {
25
31
  type="number"
26
32
  className="pair-v"
27
33
  placeholder="Participant 2"
34
+ aria-label="Participant 2"
28
35
  min="1"
36
+ inputMode="numeric"
37
+ aria-describedby={helpId}
29
38
  value={pair.v === '' || pair.v === undefined ? '' : pair.v}
30
39
  onChange={handleVChange}
31
40
  />
32
- <button type="button" className="remove-pair" onClick={onRemove}>
41
+ <button
42
+ type="button"
43
+ className="remove-pair"
44
+ onClick={onRemove}
45
+ aria-label={`Remove ${pairLabel}`}
46
+ >
33
47
  Remove
34
48
  </button>
35
- </div>
49
+ </fieldset>
36
50
  );
37
51
  }
38
52
 
@@ -1,7 +1,7 @@
1
1
  import { useState } from 'react';
2
2
  import PairInput from './PairInput';
3
3
 
4
- function ScheduleForm({ onSubmit, loading }) {
4
+ function ScheduleForm({ onSubmit, onCancel, loading, cancelling }) {
5
5
  const [participants, setParticipants] = useState('');
6
6
  const [tables, setTables] = useState('');
7
7
  const [rounds, setRounds] = useState('');
@@ -79,127 +79,187 @@ function ScheduleForm({ onSubmit, loading }) {
79
79
  };
80
80
 
81
81
  return (
82
- <section className="card" id="input-section">
83
- <h2>Schedule Parameters</h2>
82
+ <section className="card form-card" id="input-section">
83
+ <div className="section-heading">
84
+ <h2>Schedule Parameters</h2>
85
+ </div>
86
+ <p className="section-intro">
87
+ Choose your group size, tables, and rounds. Add anyone you want to bring
88
+ together or keep apart.
89
+ </p>
84
90
  <form
85
91
  id="schedule-form"
86
92
  onSubmit={handleSubmit}
87
93
  className={loading ? 'loading' : ''}
94
+ aria-busy={loading}
88
95
  >
89
- <div className="form-group">
90
- <label htmlFor="participants">Number of Participants</label>
91
- <input
92
- type="number"
93
- id="participants"
94
- name="participants"
95
- min="1"
96
- required
97
- value={participants}
98
- onChange={(e) => setParticipants(e.target.value)}
99
- />
100
- <small>Total number of participants (1..a)</small>
101
- </div>
102
-
103
- <div className="form-group">
104
- <label htmlFor="tables">Number of Tables</label>
105
- <input
106
- type="number"
107
- id="tables"
108
- name="tables"
109
- min="1"
110
- required
111
- value={tables}
112
- onChange={(e) => setTables(e.target.value)}
113
- />
114
- <small>
115
- Number of tables (1..b). Participants 1..b will be hosts.
116
- </small>
117
- </div>
118
-
119
- <div className="form-group">
120
- <label htmlFor="rounds">Number of Rounds</label>
121
- <input
122
- type="number"
123
- id="rounds"
124
- name="rounds"
125
- min="1"
126
- required
127
- value={rounds}
128
- onChange={(e) => setRounds(e.target.value)}
129
- />
130
- <small>Number of rounds to schedule</small>
131
- </div>
96
+ <div className="parameter-grid">
97
+ <div className="form-group">
98
+ <label htmlFor="participants">Number of Participants</label>
99
+ <input
100
+ type="number"
101
+ id="participants"
102
+ name="participants"
103
+ min="1"
104
+ required
105
+ aria-describedby="participants-help"
106
+ value={participants}
107
+ onChange={(e) => setParticipants(e.target.value)}
108
+ />
109
+ <small id="participants-help">
110
+ Total number of participants (1..a)
111
+ </small>
112
+ </div>
132
113
 
133
- <div className="form-group">
134
- <label htmlFor="time-limit">Time Limit (seconds)</label>
135
- <input
136
- type="number"
137
- id="time-limit"
138
- name="time-limit"
139
- min="1"
140
- max="300"
141
- value={timeLimit}
142
- onChange={(e) => setTimeLimit(parseInt(e.target.value))}
143
- />
144
- <small>Maximum time for the solver (1-300 seconds)</small>
145
- </div>
114
+ <div className="form-group">
115
+ <label htmlFor="tables">Number of Tables</label>
116
+ <input
117
+ type="number"
118
+ id="tables"
119
+ name="tables"
120
+ min="1"
121
+ required
122
+ aria-describedby="tables-help"
123
+ value={tables}
124
+ onChange={(e) => setTables(e.target.value)}
125
+ />
126
+ <small id="tables-help">
127
+ Number of tables (1..b). Participants 1..b will be hosts.
128
+ </small>
129
+ </div>
146
130
 
147
- <div className="form-group">
148
- <div className="pairs-header">
149
- <label>Same-Once Pairs</label>
150
- <button
151
- type="button"
152
- className="btn-secondary"
153
- onClick={addSameOncePair}
154
- >
155
- + Add Pair
156
- </button>
131
+ <div className="form-group">
132
+ <label htmlFor="rounds">Number of Rounds</label>
133
+ <input
134
+ type="number"
135
+ id="rounds"
136
+ name="rounds"
137
+ min="1"
138
+ required
139
+ aria-describedby="rounds-help"
140
+ value={rounds}
141
+ onChange={(e) => setRounds(e.target.value)}
142
+ />
143
+ <small id="rounds-help">Number of rounds to schedule</small>
157
144
  </div>
158
- <small>Pairs that should be seated together exactly once</small>
159
- <div className="pairs-container">
160
- {sameOncePairs.map((pair, index) => (
161
- <PairInput
162
- key={index}
163
- pair={pair}
164
- onChange={(field, value) =>
165
- updateSameOncePair(index, field, value)
166
- }
167
- onRemove={() => removeSameOncePair(index)}
168
- />
169
- ))}
145
+
146
+ <div className="form-group">
147
+ <label htmlFor="time-limit">Time Limit (seconds)</label>
148
+ <input
149
+ type="number"
150
+ id="time-limit"
151
+ name="time-limit"
152
+ min="1"
153
+ max="300"
154
+ aria-describedby="time-limit-help"
155
+ value={timeLimit}
156
+ onChange={(e) => setTimeLimit(parseInt(e.target.value))}
157
+ />
158
+ <small id="time-limit-help">
159
+ Maximum time for the solver (1-300 seconds)
160
+ </small>
170
161
  </div>
171
162
  </div>
172
163
 
173
- <div className="form-group">
174
- <div className="pairs-header">
175
- <label>Never-Together Pairs</label>
176
- <button
177
- type="button"
178
- className="btn-secondary"
179
- onClick={addNeverTogetherPair}
180
- >
181
- + Add Pair
182
- </button>
183
- </div>
184
- <small>Pairs that must never be seated together</small>
185
- <div className="pairs-container">
186
- {neverTogetherPairs.map((pair, index) => (
187
- <PairInput
188
- key={index}
189
- pair={pair}
190
- onChange={(field, value) =>
191
- updateNeverTogetherPair(index, field, value)
192
- }
193
- onRemove={() => removeNeverTogetherPair(index)}
194
- />
195
- ))}
196
- </div>
164
+ <div className="pair-rules-grid">
165
+ <fieldset className="pair-rule">
166
+ <legend>Same-Once Pairs</legend>
167
+ <div className="pairs-header">
168
+ <span className="rule-caption">A connection to make once</span>
169
+ <button
170
+ type="button"
171
+ className="btn-secondary"
172
+ onClick={addSameOncePair}
173
+ >
174
+ + Add Pair
175
+ </button>
176
+ </div>
177
+ <small id="same-once-help">
178
+ These participants should share a table in one round.
179
+ </small>
180
+ <div className="pairs-container">
181
+ {sameOncePairs.map((pair, index) => (
182
+ <PairInput
183
+ key={index}
184
+ pair={pair}
185
+ pairLabel={`Same-once pair ${index + 1}`}
186
+ helpId="same-once-help"
187
+ onChange={(field, value) =>
188
+ updateSameOncePair(index, field, value)
189
+ }
190
+ onRemove={() => removeSameOncePair(index)}
191
+ />
192
+ ))}
193
+ </div>
194
+ </fieldset>
195
+
196
+ <fieldset className="pair-rule">
197
+ <legend>Never-Together Pairs</legend>
198
+ <div className="pairs-header">
199
+ <span className="rule-caption">A combination to avoid</span>
200
+ <button
201
+ type="button"
202
+ className="btn-secondary"
203
+ onClick={addNeverTogetherPair}
204
+ >
205
+ + Add Pair
206
+ </button>
207
+ </div>
208
+ <small id="never-together-help">
209
+ Keep these participants at separate tables in every round.
210
+ </small>
211
+ <div className="pairs-container">
212
+ {neverTogetherPairs.map((pair, index) => (
213
+ <PairInput
214
+ key={index}
215
+ pair={pair}
216
+ pairLabel={`Never-together pair ${index + 1}`}
217
+ helpId="never-together-help"
218
+ onChange={(field, value) =>
219
+ updateNeverTogetherPair(index, field, value)
220
+ }
221
+ onRemove={() => removeNeverTogetherPair(index)}
222
+ />
223
+ ))}
224
+ </div>
225
+ </fieldset>
197
226
  </div>
198
227
 
199
- <button type="submit" className="btn-primary" disabled={loading}>
200
- {loading ? 'Generating...' : 'Generate Schedule'}
228
+ <button
229
+ type="submit"
230
+ className="btn-primary"
231
+ disabled={loading}
232
+ aria-busy={loading}
233
+ >
234
+ <span className="button-label">
235
+ {loading && (
236
+ <progress
237
+ className="button-spinner"
238
+ aria-label="Generating schedule"
239
+ />
240
+ )}
241
+ <span>
242
+ {loading ? 'Generating schedule…' : 'Generate Schedule'}
243
+ </span>
244
+ </span>
245
+ <span className="button-arrow" aria-hidden="true">
246
+ {loading ? '⋯' : '↗'}
247
+ </span>
201
248
  </button>
202
249
  </form>
250
+ {loading && (
251
+ <button
252
+ id="cancel-solve"
253
+ type="button"
254
+ className="btn-secondary cancel-solve-button"
255
+ onClick={onCancel}
256
+ disabled={cancelling}
257
+ aria-controls="schedule-form"
258
+ aria-label={cancelling ? 'Stopping solver' : undefined}
259
+ >
260
+ {cancelling ? 'Stopping solver…' : 'Cancel schedule generation'}
261
+ </button>
262
+ )}
203
263
  </section>
204
264
  );
205
265
  }