Skip to content

Commit 758fdcf

Browse files
authored
feat: phone_ide v2 concept (#1513)
* feat: update phone_ide dependency to use local path and refactor editor options in ChallengeView * feat: refactor ChallengeView and ChallengeViewModel to streamline editor initialization and enhance file handling * feat: update ChallengeView and ChallengeViewModel to improve file handling and editor initialization * fix: remove unused hasRegion option from EditorOptions in ChallengeViewModel * refactor: remove unused currFileType and update HTMLParser to use Editor for code highlighting * feat: update EditorOptions in HTMLParser to disable editing and linebar visibility * feat: add stream subscriptions for text field data and text changes in ChallengeViewModel * fix: simplify defaultValue assignment by using trimRight() on codeElement.text * fix: enhance resource management by adding disposeOfListeners method in ChallengeViewModel and updating onDispose in ChallengeView * fix: update phone_ide dependency to version 2.0.0
1 parent ca70e2d commit 758fdcf

File tree

6 files changed

+131
-164
lines changed

6 files changed

+131
-164
lines changed

mobile-app/lib/enums/ext_type.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
enum Ext { js, html, css, jsx }
1+
enum Ext {
2+
js('js'),
3+
html('html'),
4+
css('css'),
5+
jsx('jsx');
6+
7+
final String value;
8+
const Ext(this.value);
9+
}
210

311
Ext parseExt(String ext) {
412
switch (ext) {

mobile-app/lib/ui/views/learn/challenge/challenge_view.dart

Lines changed: 15 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ class ChallengeView extends StatelessWidget {
3535
onViewModelReady: (model) {
3636
model.init(block, challenge, challengesCompleted);
3737
},
38-
onDispose: (model) => model.closeWebViews(),
38+
onDispose: (model) {
39+
model.closeWebViews();
40+
model.disposeOfListeners();
41+
},
3942
builder: (context, model, child) {
4043
int maxChallenges = block.challenges.length;
4144
ChallengeFile currFile = model.currentFile(challenge);
@@ -44,41 +47,16 @@ class ChallengeView extends StatelessWidget {
4447

4548
bool onlyJs = challenge.files.every((file) => file.ext.name == 'js');
4649

47-
bool editableRegion = currFile.editableRegionBoundaries.isNotEmpty;
48-
EditorOptions options = EditorOptions(
49-
hasRegion: editableRegion,
50-
fontFamily: 'Hack',
51-
);
52-
53-
Editor editor = Editor(
54-
language: currFile.ext.name.toUpperCase(),
55-
options: options,
56-
);
57-
58-
model.initFile(editor, challenge, currFile, editableRegion);
59-
model.listenToFocusedController(editor);
60-
model.listenToSymbolBarScrollController();
50+
model.initFile(challenge, currFile);
6151

6252
if (model.showPanel) {
6353
FocusManager.instance.primaryFocus?.unfocus();
6454
}
6555

66-
editor.onTextChange.stream.listen((text) {
67-
model.fileService.saveFileInCache(
68-
challenge,
69-
model.currentSelectedFile,
70-
text,
56+
if (model.editor == null) {
57+
return Center(
58+
child: CircularProgressIndicator(),
7159
);
72-
73-
model.setEditorText = text;
74-
model.setHasTypedInEditor = true;
75-
model.setCompletedChallenge = false;
76-
});
77-
78-
if (editableRegion) {
79-
editor.editableRegion.stream.listen((region) {
80-
model.setEditableRegionContent = region;
81-
});
8260
}
8361

8462
BoxDecoration decoration = const BoxDecoration(
@@ -151,7 +129,6 @@ class ChallengeView extends StatelessWidget {
151129
model,
152130
challenge,
153131
file,
154-
editor,
155132
)
156133
],
157134
),
@@ -172,7 +149,6 @@ class ChallengeView extends StatelessWidget {
172149
model,
173150
keyboard,
174151
challenge,
175-
editor,
176152
context,
177153
),
178154
),
@@ -186,9 +162,9 @@ class ChallengeView extends StatelessWidget {
186162
panel: model.panelType,
187163
maxChallenges: maxChallenges,
188164
challengesCompleted: challengesCompleted,
189-
editor: editor,
165+
editor: model.editor!,
190166
),
191-
Expanded(child: editor)
167+
Expanded(child: model.editor!)
192168
],
193169
)
194170
: Column(
@@ -200,7 +176,7 @@ class ChallengeView extends StatelessWidget {
200176
panel: model.panelType,
201177
maxChallenges: maxChallenges,
202178
challengesCompleted: challengesCompleted,
203-
editor: editor,
179+
editor: model.editor!,
204180
),
205181
model.showProjectPreview && !onlyJs
206182
? ProjectPreview(
@@ -223,7 +199,6 @@ class ChallengeView extends StatelessWidget {
223199
ChallengeViewModel model,
224200
Challenge challenge,
225201
ChallengeFile file,
226-
Editor editor,
227202
) {
228203
return Expanded(
229204
child: Container(
@@ -243,31 +218,9 @@ class ChallengeView extends StatelessWidget {
243218
),
244219
onPressed: () async {
245220
model.setCurrentSelectedFile = file.name;
221+
model.setMounted = false;
246222
ChallengeFile currFile = model.currentFile(challenge);
247-
248-
String currText = await model.fileService.getExactFileFromCache(
249-
challenge,
250-
currFile,
251-
);
252-
bool hasRegion = currFile.editableRegionBoundaries.isNotEmpty;
253-
254-
editor.fileTextStream.sink.add(
255-
FileIDE(
256-
id: challenge.id + currFile.name,
257-
ext: currFile.ext.name.toUpperCase(),
258-
name: currFile.name,
259-
content: currText == '' ? currFile.contents : currText,
260-
hasRegion: currFile.editableRegionBoundaries.isNotEmpty,
261-
region: EditorRegionOptions(
262-
start:
263-
hasRegion ? currFile.editableRegionBoundaries[0] : null,
264-
end: hasRegion ? currFile.editableRegionBoundaries[1] : null,
265-
),
266-
),
267-
);
268-
269-
model.setEditorText = currText == '' ? currFile.contents : currText;
270-
model.setShowPreview = false;
223+
model.initFile(challenge, currFile);
271224
},
272225
child: Text(
273226
'${file.name}.${file.ext.name}',
@@ -288,7 +241,6 @@ class ChallengeView extends StatelessWidget {
288241
ChallengeViewModel model,
289242
bool keyboard,
290243
Challenge challenge,
291-
Editor editor,
292244
BuildContext context,
293245
) {
294246
return BottomAppBar(
@@ -300,7 +252,7 @@ class ChallengeView extends StatelessWidget {
300252
if (keyboard)
301253
SymbolBar(
302254
model: model,
303-
editor: editor,
255+
editor: model.editor!,
304256
),
305257
Row(
306258
children: [
@@ -393,38 +345,7 @@ class ChallengeView extends StatelessWidget {
393345
onPressed: () async {
394346
ChallengeFile currFile = model.currentFile(challenge);
395347

396-
String currText =
397-
await model.fileService.getExactFileFromCache(
398-
challenge,
399-
currFile,
400-
);
401-
402-
model.setMounted = false;
403-
404-
editor.fileTextStream.sink.add(FileIDE(
405-
id: challenge.id + currFile.name,
406-
ext: currFile.ext.name.toUpperCase(),
407-
name: currFile.name,
408-
content: currText == '' ? currFile.contents : currText,
409-
hasRegion: currFile.editableRegionBoundaries.isNotEmpty,
410-
region: EditorRegionOptions(
411-
start: currFile.editableRegionBoundaries.isNotEmpty
412-
? currFile.editableRegionBoundaries[0]
413-
: null,
414-
end: currFile.editableRegionBoundaries.isNotEmpty
415-
? currFile.editableRegionBoundaries[1]
416-
: null,
417-
),
418-
));
419-
model.setEditorText =
420-
currText == '' ? currFile.contents : currText;
421-
model.setShowPreview = !model.showPreview;
422-
423-
if (!model.showProjectPreview && !model.showConsole) {
424-
model.setShowProjectPreview = true;
425-
}
426-
427-
model.refresh();
348+
model.initFile(challenge, currFile);
428349
},
429350
splashColor: Colors.transparent,
430351
highlightColor: Colors.transparent,

0 commit comments

Comments
 (0)