@@ -33,23 +33,25 @@ import 'package:solidui/src/utils/path_utils.dart';
3333import 'package:solidui/src/widgets/solid_file_helpers.dart' ;
3434import 'package:solidui/src/widgets/solid_file_upload_config.dart' ;
3535
36- /// Predefined file types for different data categories .
37-
38- enum SolidFileType {
39- bloodPressure,
40- vaccination,
41- medication,
42- diary,
43- profile ,
44- general ,
45- }
36+ /// A callback type for resolving file type configurations from a path .
37+ ///
38+ /// Applications can provide their own resolver to map directory paths to
39+ /// specific [FileTypeConfig] instances. Return `null` to fall through to the
40+ /// default generic behaviour.
41+
42+ typedef FileTypeResolver = FileTypeConfig ? Function (
43+ String normalisedPath ,
44+ String ? basePath ,
45+ );
4646
4747/// Configuration for different file types.
4848
4949class FileTypeConfig {
50- /// The file type.
50+ /// A string identifier for this file type (e.g. 'general', 'blood_pressure').
51+ ///
52+ /// Applications may define their own type identifiers.
5153
52- final SolidFileType type ;
54+ final String typeId ;
5355
5456 /// Display name for the folder.
5557
@@ -84,7 +86,7 @@ class FileTypeConfig {
8486 final String uploadTooltip;
8587
8688 const FileTypeConfig ({
87- required this .type ,
89+ this .typeId = 'general' ,
8890 required this .displayName,
8991 this .showCsvButtons = false ,
9092 this .showProfileButtons = false ,
@@ -97,121 +99,58 @@ class FileTypeConfig {
9799
98100 /// Gets the file type configuration based on the current path.
99101
100- static FileTypeConfig fromPath (String currentPath, [String ? basePath]) {
102+ static FileTypeConfig fromPath (
103+ String currentPath, [
104+ String ? basePath,
105+ FileTypeResolver ? resolver,
106+ ]) {
101107 // Normalise the path for consistent pattern matching.
102108
103109 final normalisedPath = PathUtils .normalise (currentPath);
104110
105- if (normalisedPath.contains ('/blood_pressure' ) ||
106- normalisedPath.contains ('blood_pressure/' ) ||
107- normalisedPath.endsWith ('blood_pressure' )) {
108- return const FileTypeConfig (
109- type: SolidFileType .bloodPressure,
110- displayName: 'Blood Pressure Data' ,
111- showCsvButtons: true ,
112- formatConfig: SolidFileDataFormats .bloodPressure,
113- uploadTooltip: '''
111+ // Attempt app-specific resolution first.
114112
115- **Upload**: Tap here to upload a file to your Solid Health Pod.
113+ if (resolver != null ) {
114+ final resolved = resolver (normalisedPath, basePath);
115+ if (resolved != null ) return resolved;
116+ }
116117
117- ''' ,
118- );
119- } else if (normalisedPath.contains ('/vaccination' ) ||
120- normalisedPath.contains ('vaccination/' ) ||
121- normalisedPath.endsWith ('vaccination' )) {
122- return const FileTypeConfig (
123- type: SolidFileType .vaccination,
124- displayName: 'Vaccination Data' ,
125- showCsvButtons: true ,
126- formatConfig: SolidFileDataFormats .vaccination,
127- uploadTooltip: '''
128-
129- **Upload**: Tap here to upload a file to your Solid Health Pod.
118+ // Generic fallback — derive a friendly display name from the path.
130119
131- ''' ,
132- );
133- } else if (normalisedPath.contains ('/medication' ) ||
134- normalisedPath.contains ('medication/' ) ||
135- normalisedPath.endsWith ('medication' )) {
136- return const FileTypeConfig (
137- type: SolidFileType .medication,
138- displayName: 'Medication Data' ,
139- showCsvButtons: true ,
140- formatConfig: SolidFileDataFormats .medication,
141- uploadTooltip: '''
142-
143- **Upload**: Tap here to upload a file to your Solid Health Pod.
120+ String effectiveBasePath =
121+ basePath != null ? PathUtils .normalise (basePath) : '' ;
144122
145- ''' ,
146- );
147- } else if (normalisedPath.contains ('/diary' ) ||
148- normalisedPath.contains ('diary/' ) ||
149- normalisedPath.endsWith ('diary' )) {
150- return const FileTypeConfig (
151- type: SolidFileType .diary,
152- displayName: 'Appointments Data' ,
153- showCsvButtons: true ,
154- formatConfig: SolidFileDataFormats .diary,
155- uploadTooltip: '''
156-
157- **Upload**: Tap here to upload a file to your Solid Health Pod.
123+ if (effectiveBasePath.isEmpty) {
124+ final segments =
125+ normalisedPath.split ('/' ).where ((s) => s.isNotEmpty).toList ();
158126
159- ''' ,
160- );
161- } else if (normalisedPath.contains ('/profile' ) ||
162- normalisedPath.contains ('profile/' ) ||
163- normalisedPath.endsWith ('profile' )) {
164- return const FileTypeConfig (
165- type: SolidFileType .profile,
166- displayName: 'Profile Data' ,
167- showProfileButtons: true ,
168- formatConfig: SolidFileDataFormats .profile,
169- uploadTooltip: '''
170-
171- **Upload**: Tap here to upload a file to your Solid Health Pod.
127+ // Construct a reasonable base path — typically the first 2 segments
128+ // for most cases.
172129
173- ''' ,
174- );
175- } else {
176- // General case - use the existing friendly folder name logic for
177- // consistency. If basePath is provided, use it; otherwise, construct a
178- // reasonable default.
179-
180- String effectiveBasePath =
181- basePath != null ? PathUtils .normalise (basePath) : '' ;
182-
183- if (effectiveBasePath.isEmpty) {
184- final segments =
185- normalisedPath.split ('/' ).where ((s) => s.isNotEmpty).toList ();
186-
187- // Construct a reasonable base path - typically the first 2 segments
188- // for most cases.
189-
190- if (segments.length >= 2 ) {
191- effectiveBasePath = '${segments [0 ]}/${segments [1 ]}' ;
192- } else if (segments.length == 1 ) {
193- effectiveBasePath = segments[0 ];
194- }
130+ if (segments.length >= 2 ) {
131+ effectiveBasePath = '${segments [0 ]}/${segments [1 ]}' ;
132+ } else if (segments.length == 1 ) {
133+ effectiveBasePath = segments[0 ];
195134 }
135+ }
196136
197- final friendlyName = SolidFileHelpers .getFriendlyFolderName (
198- normalisedPath,
199- effectiveBasePath,
200- );
137+ final friendlyName = SolidFileHelpers .getFriendlyFolderName (
138+ normalisedPath,
139+ effectiveBasePath,
140+ );
201141
202- String displayName =
203- friendlyName == 'Home' ? 'Home Folder' : friendlyName;
142+ String displayName =
143+ friendlyName == 'Home' ? 'Home Folder' : friendlyName;
204144
205- return FileTypeConfig (
206- type : SolidFileType . general,
207- displayName: displayName,
208- uploadTooltip: '''
145+ return FileTypeConfig (
146+ typeId : ' general' ,
147+ displayName: displayName,
148+ uploadTooltip: '''
209149
210- **Upload**: Tap here to upload a file to your Solid Health Pod.
150+ **Upload**: Tap here to upload a file to your Solid Pod.
211151
212152''' ,
213- );
214- }
153+ );
215154 }
216155
217156 /// Creates the upload configuration for this file type.
0 commit comments