Code cleanup
This commit is contained in:
parent
c9f6b0460a
commit
6a87c3da75
|
|
@ -120,7 +120,7 @@ abstract class DocumentEntity extends Object
|
||||||
: '${round(size / 1000, 0).toInt()} KB';
|
: '${round(size / 1000, 0).toInt()} KB';
|
||||||
|
|
||||||
String previewUrl(String baseUrl) =>
|
String previewUrl(String baseUrl) =>
|
||||||
formatApiUrlMachine(
|
formatApiUrl(
|
||||||
baseUrl != null && baseUrl.startsWith('http') ? baseUrl : kAppUrl) +
|
baseUrl != null && baseUrl.startsWith('http') ? baseUrl : kAppUrl) +
|
||||||
'/documents/$id';
|
'/documents/$id';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ class AuthRepository {
|
||||||
'one_time_password': oneTimePassword,
|
'one_time_password': oneTimePassword,
|
||||||
};
|
};
|
||||||
|
|
||||||
url = formatApiUrlMachine(url) + '/login';
|
url = formatApiUrl(url) + '/login';
|
||||||
|
|
||||||
return sendRequest(url: url, data: credentials);
|
return sendRequest(url: url, data: credentials);
|
||||||
}
|
}
|
||||||
|
|
@ -42,7 +42,7 @@ class AuthRepository {
|
||||||
'token': token,
|
'token': token,
|
||||||
'provider': 'google',
|
'provider': 'google',
|
||||||
};
|
};
|
||||||
url = formatApiUrlMachine(url) + '/oauth_login';
|
url = formatApiUrl(url) + '/oauth_login';
|
||||||
|
|
||||||
return sendRequest(url: url, data: credentials);
|
return sendRequest(url: url, data: credentials);
|
||||||
}
|
}
|
||||||
|
|
@ -53,7 +53,7 @@ class AuthRepository {
|
||||||
'token_name': 'invoice-ninja-$platform-app',
|
'token_name': 'invoice-ninja-$platform-app',
|
||||||
};
|
};
|
||||||
|
|
||||||
url = formatApiUrlMachine(url) + '/refresh';
|
url = formatApiUrl(url) + '/refresh';
|
||||||
|
|
||||||
return sendRequest(url: url, data: credentials, token: token);
|
return sendRequest(url: url, data: credentials, token: token);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -266,7 +266,8 @@ abstract class AppState implements Built<AppState, AppStateBuilder> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'Is Testing: ${uiState.isTesting}';
|
return 'URL: ${authState.url}';
|
||||||
|
//return 'Is Testing: ${uiState.isTesting}';
|
||||||
//return 'Route: ${uiState.currentRoute}, Previous: ${uiState.previousRoute}, Layout: ${uiState.layout}, Menu: ${uiState.isMenuVisible}, History: ${uiState.isHistoryVisible}';
|
//return 'Route: ${uiState.currentRoute}, Previous: ${uiState.previousRoute}, Layout: ${uiState.layout}, Menu: ${uiState.isMenuVisible}, History: ${uiState.isHistoryVisible}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,8 @@ void _saveAuthLocal({String email, String url, String secret}) async {
|
||||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||||
prefs.setString(kSharedPrefEmail, email ?? '');
|
prefs.setString(kSharedPrefEmail, email ?? '');
|
||||||
|
|
||||||
if (formatApiUrlReadable(url) != kAppUrl) {
|
if (cleanApiUrl(url).isNotEmpty && cleanApiUrl(url) != kAppUrl) {
|
||||||
prefs.setString(kSharedPrefUrl, formatApiUrlMachine(url));
|
prefs.setString(kSharedPrefUrl, formatApiUrl(url));
|
||||||
prefs.setString(kSharedPrefSecret, secret);
|
prefs.setString(kSharedPrefSecret, secret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -39,7 +39,7 @@ void _saveAuthLocal({String email, String url, String secret}) async {
|
||||||
void _loadAuthLocal(Store<AppState> store) async {
|
void _loadAuthLocal(Store<AppState> store) async {
|
||||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||||
final String email = prefs.getString(kSharedPrefEmail) ?? '';
|
final String email = prefs.getString(kSharedPrefEmail) ?? '';
|
||||||
final String url = formatApiUrlMachine(prefs.getString(kSharedPrefUrl) ?? '');
|
final String url = formatApiUrl(prefs.getString(kSharedPrefUrl) ?? '');
|
||||||
final String secret = prefs.getString(kSharedPrefSecret) ?? '';
|
final String secret = prefs.getString(kSharedPrefSecret) ?? '';
|
||||||
store.dispatch(UserLoginLoaded(email, url, secret));
|
store.dispatch(UserLoginLoaded(email, url, secret));
|
||||||
|
|
||||||
|
|
@ -153,7 +153,7 @@ Middleware<AppState> _createRefreshRequest(AuthRepository repository) {
|
||||||
|
|
||||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||||
final String url =
|
final String url =
|
||||||
formatApiUrlMachine(prefs.getString(kSharedPrefUrl) ?? Config.TEST_URL);
|
formatApiUrl(prefs.getString(kSharedPrefUrl) ?? Config.TEST_URL);
|
||||||
final String token = prefs.getString(getCompanyTokenKey());
|
final String token = prefs.getString(getCompanyTokenKey());
|
||||||
|
|
||||||
repository
|
repository
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ AuthState userLoginRequestReducer(
|
||||||
AuthState authState, UserLoginRequest action) {
|
AuthState authState, UserLoginRequest action) {
|
||||||
return authState.rebuild((b) => b
|
return authState.rebuild((b) => b
|
||||||
..error = null
|
..error = null
|
||||||
..url = formatApiUrlMachine(action.url)
|
..url = formatApiUrl(action.url)
|
||||||
..secret = action.secret
|
..secret = action.secret
|
||||||
..email = action.email
|
..email = action.email
|
||||||
..password = action.password);
|
..password = action.password);
|
||||||
|
|
@ -38,7 +38,7 @@ AuthState oauthLoginRequestReducer(
|
||||||
AuthState authState, OAuthLoginRequest action) {
|
AuthState authState, OAuthLoginRequest action) {
|
||||||
return authState.rebuild((b) => b
|
return authState.rebuild((b) => b
|
||||||
..error = null
|
..error = null
|
||||||
..url = formatApiUrlMachine(action.url)
|
..url = formatApiUrl(action.url)
|
||||||
..secret = action.secret);
|
..secret = action.secret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,10 +41,10 @@ class _LoginState extends State<LoginView> {
|
||||||
final state = widget.viewModel.authState;
|
final state = widget.viewModel.authState;
|
||||||
_emailController.text = state.email;
|
_emailController.text = state.email;
|
||||||
_passwordController.text = state.password;
|
_passwordController.text = state.password;
|
||||||
_urlController.text = formatApiUrlReadable(state.url);
|
_urlController.text = cleanApiUrl(state.url);
|
||||||
_secretController.text = state.secret;
|
_secretController.text = state.secret;
|
||||||
|
|
||||||
if (state.url.isNotEmpty) {
|
if (cleanApiUrl(state.url).isNotEmpty) {
|
||||||
_isSelfHosted = true;
|
_isSelfHosted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -277,9 +277,9 @@ String formatDate(String value, BuildContext context,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String formatApiUrlMachine(String url) => formatApiUrlReadable(url) + '/api/v1';
|
String formatApiUrl(String url) => cleanApiUrl(url) + '/api/v1';
|
||||||
|
|
||||||
String formatApiUrlReadable(String url) => url
|
String cleanApiUrl(String url) => url
|
||||||
.trim()
|
.trim()
|
||||||
.replaceFirst(RegExp(r'/api/v1'), '')
|
.replaceFirst(RegExp(r'/api/v1'), '')
|
||||||
.replaceFirst(RegExp(r'/$'), '');
|
.replaceFirst(RegExp(r'/$'), '');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue