Skip to content

Commit 760661f

Browse files
committed
Create CodelesslyConstants
1 parent 8f64b0c commit 760661f

File tree

6 files changed

+51
-92
lines changed

6 files changed

+51
-92
lines changed

lib/src/auth/auth_manager.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ class AuthManager {
9797
// Codelessly Cloud Data to work.
9898
_idTokenResult = await firebaseAuth.currentUser!.getIdTokenResult(true);
9999

100-
if (cacheManager.isCached(authCacheKey)) {
100+
if (cacheManager.isCached('auth')) {
101101
try {
102102
final AuthData cachedAuthData = cacheManager.get<AuthData>(
103-
authCacheKey,
103+
'auth',
104104
decode: AuthData.fromJson,
105105
);
106106

@@ -376,14 +376,14 @@ class AuthManager {
376376
_authData = authData;
377377
_authStreamController.add(_authData!);
378378

379-
await cacheManager.store(authCacheKey, _authData!.toJson());
379+
await cacheManager.store('auth', _authData!.toJson());
380380
DebugLogger.instance.printInfo('Stored auth data in cache', name: name);
381381
DebugLogger.instance
382382
.printInfo('Authentication successfully!', name: name);
383383
} else {
384384
_authData = null;
385385
_authStreamController.add(_authData);
386-
await cacheManager.delete(authCacheKey);
386+
await cacheManager.delete('auth');
387387
DebugLogger.instance
388388
.printInfo('Failed to authenticate token.', name: name);
389389

lib/src/cache/codelessly_cache_manager.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ class CodelesslyCacheManager extends CacheManager {
3333
try {
3434
await Hive.initFlutter('codelessly_sdk');
3535
box = await Hive.openBox(
36-
'${cacheBoxName}_${config.uniqueID.replaceAll('/', '')}',
36+
'cache_${config.uniqueID.replaceAll('/', '')}',
3737
);
3838
filesBox = await Hive.openBox(
39-
'${cacheFilesBoxName}_${config.uniqueID.replaceAll('/', '')}',
39+
'cache_files_${config.uniqueID.replaceAll('/', '')}',
4040
);
4141
} catch (e, str) {
4242
ErrorLogger.instance.captureException(

lib/src/codelessly_config.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,12 @@ class CodelesslyConfig with EquatableMixin {
100100
this.isPreview = false,
101101
this.preload = true,
102102
FirebaseOptions? firebaseOptions,
103-
this.firebaseInstanceName = kCodelesslyFirebaseApp,
104-
this.firebaseCloudFunctionsBaseURL = kProdCloudFunctionsBaseURL,
105-
this.baseURL = kProdBaseURL,
103+
this.firebaseInstanceName = CodelesslyConstants.kCodelesslyFirebaseApp,
104+
this.firebaseCloudFunctionsBaseURL =
105+
CodelesslyConstants.kProdCloudFunctionsBaseURL,
106+
this.baseURL = CodelesslyConstants.kProdBaseURL,
106107
this.clientType = 'default_client',
107-
this.firebaseProjectId = kProdFirebaseProjectId,
108+
this.firebaseProjectId = CodelesslyConstants.kProdFirebaseProjectId,
108109
PublishSource? publishSource,
109110
this.debugLog = false,
110111
}) : firebaseOptions =

lib/src/constants.dart

Lines changed: 13 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,13 @@
1-
/// The unique identifier for the Codelessly Firebase app instance.
2-
const String kCodelesslyFirebaseApp = 'codelessly';
3-
4-
/// Production environment constants
5-
const String kProdFirebaseProjectId = 'codeless-app';
6-
const String kProdCloudFunctionsBaseURL =
7-
'https://us-central1-codeless-app.cloudfunctions.net';
8-
const String kProdBaseURL = 'https://app.codelessly.com';
9-
10-
/// Editor identifier constant
11-
const String kCodelesslyEditor = 'codelessly_editor';
12-
13-
/// Default error message for rendering failures
14-
const String defaultErrorMessage = 'Error rendering page.';
15-
16-
/// Cache-related constants
17-
const String cacheBoxName = 'cache';
18-
const String cacheFilesBoxName = 'cache_files';
19-
const String authCacheKey = 'auth';
20-
21-
/// Model cache keys
22-
const String publishModelCacheKey = 'publish_layout_model';
23-
const String previewModelCacheKey = 'preview_layout_model';
24-
const String templateModelCacheKey = 'template_layout_model';
25-
26-
/// Font cache keys
27-
const String publishFontsCacheKey = 'publish_fonts';
28-
const String previewFontsCacheKey = 'preview_fonts';
29-
const String templateFontsCacheKey = 'template_fonts';
30-
31-
/// API cache keys
32-
const String publishApisCacheKey = 'publish_apis';
33-
const String previewApisCacheKey = 'preview_apis';
34-
const String templateApisCacheKey = 'template_apis';
35-
36-
/// Variable cache keys
37-
const String publishVariablesCacheKey = 'publish_variables';
38-
const String previewVariablesCacheKey = 'preview_variables';
39-
const String templateVariablesCacheKey = 'template_variables';
40-
41-
/// Condition cache keys
42-
const String publishConditionsCacheKey = 'publish_conditions';
43-
const String previewConditionsCacheKey = 'preview_conditions';
44-
const String templateConditionsCacheKey = 'template_conditions';
45-
46-
/// Path constants
47-
const String publishPath = 'publish';
48-
const String previewPath = 'publish_preview';
49-
const String templatesPath = 'templates';
50-
51-
/// The template url for the svg icons.
52-
/// {{style}}: The style of the icon. e.g. materialiconsoutlined
53-
/// {{name}}: The name of the icon. e.g. home
54-
/// {{version}}: The version of the icon. e.g. 16
55-
/// {{size}}: The size of the icon. e.g. 24
56-
const String kSvgIconBaseUrlTemplate =
57-
'https://fonts.gstatic.com/s/i/{{style}}/{{name}}/v{{version}}/{{size}}px.svg';
1+
class CodelesslyConstants {
2+
/// The unique identifier for the Codelessly Firebase app instance.
3+
static const String kCodelesslyFirebaseApp = 'codelessly';
4+
5+
/// Production environment constants
6+
static const String kProdFirebaseProjectId = 'codeless-app';
7+
static const String kProdCloudFunctionsBaseURL =
8+
'https://us-central1-codeless-app.cloudfunctions.net';
9+
static const String kProdBaseURL = 'https://app.codelessly.com';
10+
11+
/// Editor identifier constant
12+
static const String kCodelesslyEditor = 'codelessly_editor';
13+
}

lib/src/model/publish_source.dart

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import '../../codelessly_sdk.dart';
2-
31
/// Defines the server-sided source a publish model should be retrieved from.
42
enum PublishSource {
53
/// The publish collection.
@@ -29,50 +27,50 @@ enum PublishSource {
2927

3028
/// The path to the publish model collection.
3129
String get serverPath => switch (this) {
32-
PublishSource.publish => publishPath,
33-
PublishSource.preview => previewPath,
34-
PublishSource.template => templatesPath,
30+
PublishSource.publish => 'publish',
31+
PublishSource.preview => 'publish_preview',
32+
PublishSource.template => 'templates',
3533
};
3634

3735
/// The path to the mirrored or opposite collection.
3836
String get mirroredServerPath => switch (this) {
39-
PublishSource.publish => previewPath,
40-
PublishSource.preview => publishPath,
41-
PublishSource.template => publishPath,
37+
PublishSource.publish => 'publish_preview',
38+
PublishSource.preview => 'publish',
39+
PublishSource.template => 'publish',
4240
};
4341

4442
/// The cache key for the published model.
4543
String get modelCacheKey => switch (this) {
46-
PublishSource.publish => publishModelCacheKey,
47-
PublishSource.preview => previewModelCacheKey,
48-
PublishSource.template => templateModelCacheKey,
44+
PublishSource.publish => 'publish_layout_model',
45+
PublishSource.preview => 'preview_layout_model',
46+
PublishSource.template => 'template_layout_model',
4947
};
5048

5149
/// The cache key for the font files.
5250
String get fontsCacheKey => switch (this) {
53-
PublishSource.publish => publishFontsCacheKey,
54-
PublishSource.preview => previewFontsCacheKey,
55-
PublishSource.template => templateFontsCacheKey,
51+
PublishSource.publish => 'publish_fonts',
52+
PublishSource.preview => 'preview_fonts',
53+
PublishSource.template => 'template_fonts',
5654
};
5755

5856
/// The cache key for the APIs.
5957
String get apisCacheKey => switch (this) {
60-
PublishSource.publish => publishApisCacheKey,
61-
PublishSource.preview => previewApisCacheKey,
62-
PublishSource.template => templateApisCacheKey,
58+
PublishSource.publish => 'publish_apis',
59+
PublishSource.preview => 'preview_apis',
60+
PublishSource.template => 'template_apis',
6361
};
6462

6563
/// The cache key for the APIs.
6664
String get variablesCacheKey => switch (this) {
67-
PublishSource.publish => publishVariablesCacheKey,
68-
PublishSource.preview => previewVariablesCacheKey,
69-
PublishSource.template => templateVariablesCacheKey,
65+
PublishSource.publish => 'publish_variables',
66+
PublishSource.preview => 'preview_variables',
67+
PublishSource.template => 'template_variables',
7068
};
7169

7270
/// The cache key for the APIs.
7371
String get conditionsCacheKey => switch (this) {
74-
PublishSource.publish => publishConditionsCacheKey,
75-
PublishSource.preview => previewConditionsCacheKey,
76-
PublishSource.template => templateConditionsCacheKey,
72+
PublishSource.publish => 'publish_conditions',
73+
PublishSource.preview => 'preview_conditions',
74+
PublishSource.template => 'template_conditions',
7775
};
7876
}

lib/src/utils/extensions.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,8 +1133,12 @@ extension IconModelExt on IconModel {
11331133
if (this is MaterialIcon) {
11341134
final icon = this as MaterialIcon;
11351135
// e.g https://fonts.gstatic.com/s/i/materialiconsoutlined/home/v16/24px.svg
1136-
// TODO: how to get the right version?
1137-
return kSvgIconBaseUrlTemplate
1136+
/// The template url for the svg icons.
1137+
/// {{style}}: The style of the icon. e.g. materialiconsoutlined
1138+
/// {{name}}: The name of the icon. e.g. home
1139+
/// {{version}}: The version of the icon. e.g. 16
1140+
/// {{size}}: The size of the icon. e.g. 24
1141+
return 'https://fonts.gstatic.com/s/i/{{style}}/{{name}}/v{{version}}/{{size}}px.svg'
11381142
.replaceAll(
11391143
'{{style}}', 'materialicons${icon.style.styleName.toLowerCase()}')
11401144
.replaceAll('{{name}}', icon.name.toLowerCase())

0 commit comments

Comments
 (0)