Fix: Refactor code for improved readability and consistency in document viewer and signup form
This commit is contained in:
@@ -363,11 +363,7 @@ class _DocumentViewerModalState extends State<DocumentViewerModal> {
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.error_outline,
|
||||
size: 64,
|
||||
color: Colors.red[400],
|
||||
),
|
||||
Icon(Icons.error_outline, size: 64, color: Colors.red[400]),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Failed to load document',
|
||||
@@ -406,7 +402,8 @@ class _DocumentViewerModalState extends State<DocumentViewerModal> {
|
||||
final wopiSession = snapshot.data!;
|
||||
|
||||
// Build Collabora Online viewer URL with WOPISrc
|
||||
final collaboraUrl = 'https://of.b0esche.cloud/loleaflet/dist/loleaflet.html?WOPISrc=${Uri.encodeComponent(wopiSession.wopisrc)}';
|
||||
final collaboraUrl =
|
||||
'https://of.b0esche.cloud/loleaflet/dist/loleaflet.html?WOPISrc=${Uri.encodeComponent(wopiSession.wopisrc)}';
|
||||
|
||||
// Use WebView to display Collabora Online
|
||||
return _buildWebView(collaboraUrl);
|
||||
@@ -427,13 +424,15 @@ class _DocumentViewerModalState extends State<DocumentViewerModal> {
|
||||
endpoint = '/user/files/${widget.fileId}/wopi-session';
|
||||
}
|
||||
|
||||
final response = await http.post(
|
||||
final response = await http
|
||||
.post(
|
||||
Uri.parse('$baseUrl$endpoint'),
|
||||
headers: {
|
||||
'Authorization': 'Bearer $token',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
).timeout(const Duration(seconds: 10));
|
||||
)
|
||||
.timeout(const Duration(seconds: 10));
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final json = jsonDecode(response.body) as Map<String, dynamic>;
|
||||
@@ -442,7 +441,9 @@ class _DocumentViewerModalState extends State<DocumentViewerModal> {
|
||||
accessToken: json['access_token'] as String,
|
||||
);
|
||||
} else {
|
||||
throw Exception('Failed to create WOPI session: ${response.statusCode}');
|
||||
throw Exception(
|
||||
'Failed to create WOPI session: ${response.statusCode}',
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
throw Exception('Error creating WOPI session: $e');
|
||||
@@ -459,7 +460,11 @@ class _DocumentViewerModalState extends State<DocumentViewerModal> {
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(Icons.description, size: 64, color: AppTheme.accentColor),
|
||||
const Icon(
|
||||
Icons.description,
|
||||
size: 64,
|
||||
color: AppTheme.accentColor,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Collabora Online Viewer',
|
||||
@@ -476,7 +481,9 @@ class _DocumentViewerModalState extends State<DocumentViewerModal> {
|
||||
onPressed: () {
|
||||
// You can implement opening in browser or using webview here
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Collabora viewer loading...')),
|
||||
const SnackBar(
|
||||
content: Text('Collabora viewer loading...'),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: const Text('Open Document'),
|
||||
@@ -500,10 +507,7 @@ class WOPISession {
|
||||
final String wopisrc;
|
||||
final String accessToken;
|
||||
|
||||
WOPISession({
|
||||
required this.wopisrc,
|
||||
required this.accessToken,
|
||||
});
|
||||
WOPISession({required this.wopisrc, required this.accessToken});
|
||||
|
||||
factory WOPISession.fromJson(Map<String, dynamic> json) {
|
||||
return WOPISession(
|
||||
@@ -799,11 +803,7 @@ class _DocumentViewerState extends State<DocumentViewer> {
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.description,
|
||||
size: 64,
|
||||
color: AppTheme.accentColor,
|
||||
),
|
||||
Icon(Icons.description, size: 64, color: AppTheme.accentColor),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Office Document',
|
||||
@@ -816,24 +816,16 @@ class _DocumentViewerState extends State<DocumentViewer> {
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'Collabora Online Viewer',
|
||||
style: TextStyle(
|
||||
color: AppTheme.secondaryText,
|
||||
fontSize: 14,
|
||||
),
|
||||
style: TextStyle(color: AppTheme.secondaryText, fontSize: 14),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Opening document in Collabora...',
|
||||
style: TextStyle(
|
||||
color: AppTheme.secondaryText,
|
||||
fontSize: 12,
|
||||
),
|
||||
style: TextStyle(color: AppTheme.secondaryText, fontSize: 12),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
CircularProgressIndicator(
|
||||
valueColor: AlwaysStoppedAnimation<Color>(
|
||||
AppTheme.accentColor,
|
||||
),
|
||||
valueColor: AlwaysStoppedAnimation<Color>(AppTheme.accentColor),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
ElevatedButton.icon(
|
||||
|
||||
@@ -29,7 +29,6 @@ class _SignupFormState extends State<SignupForm> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
|
||||
String _generateRandomBase64(int bytes) {
|
||||
final random = Random();
|
||||
final values = List<int>.generate(bytes, (i) => random.nextInt(256));
|
||||
|
||||
@@ -674,4 +674,5 @@ func (db *DB) MarkChallengeUsed(ctx context.Context, challenge []byte) error {
|
||||
`, challenge)
|
||||
return err
|
||||
}
|
||||
|
||||
// UpdateFileSize updates the size and last_modified timestamp of a file
|
||||
|
||||
Reference in New Issue
Block a user