mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-07-18 11:20:16 +08:00
Remove the entire concept of a subFolder
When configuring the Git Repo server, we could optionally track one folder in the root git repo, instead of just the root folder. This was specifically to address my use case where I have my journals in a sub-directory. The setup screen was super ugly, though. Since now I'm in the process of adding folder support because of #18, I can remove this hack. It simplifies the code a lot.
This commit is contained in:
@ -14,12 +14,10 @@ Future migrateGitRepo({
|
||||
@required String gitBasePath,
|
||||
@required String fromGitBasePath,
|
||||
@required String toGitBaseFolder,
|
||||
@required String toGitBaseSubFolder,
|
||||
}) async {
|
||||
Fimber.d(
|
||||
"migrateGitRepo $fromGitBasePath $toGitBaseFolder / $toGitBaseSubFolder");
|
||||
Fimber.d("migrateGitRepo $fromGitBasePath $toGitBaseFolder");
|
||||
var fromBasePath = p.join(gitBasePath, fromGitBasePath);
|
||||
var toGitRepoPath = p.join(gitBasePath, toGitBaseFolder, toGitBaseSubFolder);
|
||||
var toGitRepoPath = p.join(gitBasePath, toGitBaseFolder);
|
||||
Fimber.d("toGitRemotePath $toGitRepoPath");
|
||||
|
||||
final dir = Directory(fromBasePath);
|
||||
|
@ -12,7 +12,6 @@ class AppState {
|
||||
|
||||
// FIXME: Rename from 'path' to folderName
|
||||
String remoteGitRepoFolderName = "";
|
||||
String remoteGitRepoSubFolder = "";
|
||||
bool remoteGitRepoConfigured = false;
|
||||
|
||||
bool onBoardingCompleted = false;
|
||||
@ -34,7 +33,6 @@ class AppState {
|
||||
remoteGitRepoConfigured = pref.getBool("remoteGitRepoConfigured") ?? false;
|
||||
localGitRepoPath = pref.getString("localGitRepoPath") ?? "";
|
||||
remoteGitRepoFolderName = pref.getString("remoteGitRepoPath") ?? "";
|
||||
remoteGitRepoSubFolder = pref.getString("remoteGitRepoSubFolder") ?? "";
|
||||
onBoardingCompleted = pref.getBool("onBoardingCompleted") ?? false;
|
||||
}
|
||||
|
||||
@ -44,7 +42,6 @@ class AppState {
|
||||
Fimber.d("remoteGitRepoConfigured: $remoteGitRepoConfigured");
|
||||
Fimber.d("localGitRepoPath: $localGitRepoPath");
|
||||
Fimber.d("remoteGitRepoFolderName: $remoteGitRepoFolderName");
|
||||
Fimber.d("remoteGitRepoSubFolder: $remoteGitRepoSubFolder");
|
||||
Fimber.d("onBoardingCompleted: $onBoardingCompleted");
|
||||
Fimber.d(" ------------------ ");
|
||||
}
|
||||
@ -54,7 +51,6 @@ class AppState {
|
||||
await pref.setBool("remoteGitRepoConfigured", remoteGitRepoConfigured);
|
||||
await pref.setString("localGitRepoPath", localGitRepoPath);
|
||||
await pref.setString("remoteGitRepoPath", remoteGitRepoFolderName);
|
||||
await pref.setString("remoteGitRepoSubFolder", remoteGitRepoSubFolder);
|
||||
await pref.setBool("onBoardingCompleted", onBoardingCompleted);
|
||||
}
|
||||
}
|
||||
|
@ -104,7 +104,6 @@ class GitApp extends StatelessWidget {
|
||||
await migrateGitRepo(
|
||||
fromGitBasePath: "journal_local",
|
||||
toGitBaseFolder: "journal",
|
||||
toGitBaseSubFolder: "",
|
||||
gitBasePath: baseGitPath.path,
|
||||
);
|
||||
},
|
||||
|
@ -1,77 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:function_types/function_types.dart';
|
||||
|
||||
import 'githostsetup_button.dart';
|
||||
|
||||
class GitHostSetupFolderPage extends StatelessWidget {
|
||||
final List<String> folders;
|
||||
final Func0<void> rootFolderSelected;
|
||||
final Func1<String, void> subFolderSelected;
|
||||
|
||||
GitHostSetupFolderPage({
|
||||
@required this.folders,
|
||||
@required this.rootFolderSelected,
|
||||
@required this.subFolderSelected,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var columns = Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text(
|
||||
'Would you like to store your journal entries in an existing folder?',
|
||||
style: Theme.of(context).textTheme.title,
|
||||
),
|
||||
const SizedBox(height: 32.0),
|
||||
FolderListWidget(
|
||||
folders: folders,
|
||||
onSelected: subFolderSelected,
|
||||
),
|
||||
const SizedBox(height: 16.0),
|
||||
GitHostSetupButton(
|
||||
text: "Ignore",
|
||||
onPressed: rootFolderSelected,
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
return Center(
|
||||
child: SingleChildScrollView(
|
||||
child: columns,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: This needs to be made much much prettier!
|
||||
class FolderListWidget extends StatelessWidget {
|
||||
final List<String> folders;
|
||||
final Func1<String, void> onSelected;
|
||||
|
||||
FolderListWidget({
|
||||
@required this.folders,
|
||||
@required this.onSelected,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var buttons = <Widget>[];
|
||||
for (var folderName in folders) {
|
||||
var button = GitHostSetupButton(
|
||||
text: folderName,
|
||||
onPressed: () {
|
||||
onSelected(folderName);
|
||||
},
|
||||
);
|
||||
buttons.add(button);
|
||||
}
|
||||
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: buttons,
|
||||
);
|
||||
}
|
||||
}
|
@ -17,11 +17,10 @@ import 'githostsetup_autoconfigure.dart';
|
||||
import 'githostsetup_button.dart';
|
||||
import 'githostsetup_clone.dart';
|
||||
import 'githostsetup_clone_url.dart';
|
||||
import 'githostsetup_folder.dart';
|
||||
import 'githostsetup_sshkey.dart';
|
||||
|
||||
class GitHostSetupScreen extends StatefulWidget {
|
||||
final Func1<String, void> onCompletedFunction;
|
||||
final Func0<void> onCompletedFunction;
|
||||
|
||||
GitHostSetupScreen(this.onCompletedFunction);
|
||||
|
||||
@ -46,7 +45,6 @@ class GitHostSetupScreenState extends State<GitHostSetupScreen> {
|
||||
var _gitCloneUrl = "";
|
||||
var gitCloneErrorMessage = "";
|
||||
var publicKey = "";
|
||||
var _subFolders = <String>[];
|
||||
|
||||
var pageController = PageController();
|
||||
int _currentPageIndex = 0;
|
||||
@ -188,37 +186,13 @@ class GitHostSetupScreenState extends State<GitHostSetupScreen> {
|
||||
}
|
||||
|
||||
if (pos == 4) {
|
||||
if (_pageChoice[0] == PageChoice0.CustomProvider) {
|
||||
return GitHostSetupFolderPage(
|
||||
folders: _subFolders,
|
||||
subFolderSelected: _subFolderSelected,
|
||||
rootFolderSelected: _finish,
|
||||
);
|
||||
}
|
||||
|
||||
if (_pageChoice[1] == PageChoice1.Manual) {
|
||||
return GitHostSetupGitClone(errorMessage: gitCloneErrorMessage);
|
||||
} else if (_pageChoice[1] == PageChoice1.Auto) {
|
||||
return GitHostSetupFolderPage(
|
||||
folders: _subFolders,
|
||||
subFolderSelected: _subFolderSelected,
|
||||
rootFolderSelected: _finish,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
assert(_pageChoice[0] != PageChoice0.CustomProvider);
|
||||
|
||||
if (pos == 5) {
|
||||
if (_pageChoice[1] == PageChoice1.Manual) {
|
||||
return GitHostSetupFolderPage(
|
||||
folders: _subFolders,
|
||||
subFolderSelected: _subFolderSelected,
|
||||
rootFolderSelected: _finish,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
assert(false);
|
||||
return null;
|
||||
}
|
||||
@ -412,18 +386,12 @@ class GitHostSetupScreenState extends State<GitHostSetupScreen> {
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> subFolders = await _getSubFoldersWithMdFiles(basePath);
|
||||
if (subFolders.isEmpty) {
|
||||
Fimber.d("Found no subfolders with md files");
|
||||
_finish();
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_subFolders = subFolders;
|
||||
_pageCount += 1;
|
||||
_nextPage();
|
||||
});
|
||||
getAnalytics().logEvent(
|
||||
name: "onboarding_complete",
|
||||
parameters: <String, dynamic>{},
|
||||
);
|
||||
Navigator.pop(context);
|
||||
widget.onCompletedFunction();
|
||||
}
|
||||
|
||||
Future _removeExistingClone(String baseDirPath) async {
|
||||
@ -436,55 +404,6 @@ class GitHostSetupScreenState extends State<GitHostSetupScreen> {
|
||||
await baseDir.create();
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<String>> _getSubFoldersWithMdFiles(String baseDirPath) async {
|
||||
var subFolders = <String>[];
|
||||
|
||||
var gitRootDir = Directory(p.join(baseDirPath, "journal"));
|
||||
var lister = gitRootDir.list(recursive: false);
|
||||
await for (var fileEntity in lister) {
|
||||
if (fileEntity is! Directory) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Directory dir = fileEntity;
|
||||
var hasMdFiles = await _hasMdFiles(dir);
|
||||
if (hasMdFiles) {
|
||||
subFolders.add(p.basename(dir.path));
|
||||
}
|
||||
}
|
||||
|
||||
return subFolders;
|
||||
}
|
||||
|
||||
Future<bool> _hasMdFiles(Directory dir) async {
|
||||
var lister = dir.list(recursive: false);
|
||||
await for (var fileEntity in lister) {
|
||||
if (fileEntity is! File) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (fileEntity.path.toLowerCase().endsWith('.md')) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void _finish() {
|
||||
String subFolder = "";
|
||||
_subFolderSelected(subFolder);
|
||||
}
|
||||
|
||||
void _subFolderSelected(String folder) {
|
||||
getAnalytics().logEvent(
|
||||
name: "onboarding_complete",
|
||||
parameters: <String, dynamic>{},
|
||||
);
|
||||
Navigator.pop(context);
|
||||
widget.onCompletedFunction(folder);
|
||||
}
|
||||
}
|
||||
|
||||
class GitHostChoicePage extends StatelessWidget {
|
||||
|
@ -49,13 +49,11 @@ class StateContainerState extends State<StateContainer> {
|
||||
noteRepo = GitNoteRepository(
|
||||
baseDirectory: appState.gitBaseDirectory,
|
||||
dirName: appState.remoteGitRepoFolderName,
|
||||
subDirName: appState.remoteGitRepoSubFolder,
|
||||
);
|
||||
} else if (appState.localGitRepoConfigured) {
|
||||
noteRepo = GitNoteRepository(
|
||||
baseDirectory: appState.gitBaseDirectory,
|
||||
dirName: appState.localGitRepoPath,
|
||||
subDirName: "",
|
||||
);
|
||||
}
|
||||
|
||||
@ -213,23 +211,20 @@ class StateContainerState extends State<StateContainer> {
|
||||
});
|
||||
}
|
||||
|
||||
void completeGitHostSetup(String subFolder) {
|
||||
void completeGitHostSetup() {
|
||||
() async {
|
||||
appState.remoteGitRepoConfigured = true;
|
||||
appState.remoteGitRepoFolderName = "journal";
|
||||
appState.remoteGitRepoSubFolder = subFolder;
|
||||
|
||||
await migrateGitRepo(
|
||||
fromGitBasePath: appState.localGitRepoPath,
|
||||
toGitBaseFolder: appState.remoteGitRepoFolderName,
|
||||
toGitBaseSubFolder: appState.remoteGitRepoSubFolder,
|
||||
gitBasePath: appState.gitBaseDirectory,
|
||||
);
|
||||
|
||||
noteRepo = GitNoteRepository(
|
||||
baseDirectory: appState.gitBaseDirectory,
|
||||
dirName: appState.remoteGitRepoFolderName,
|
||||
subDirName: appState.remoteGitRepoSubFolder,
|
||||
);
|
||||
|
||||
await _persistConfig();
|
||||
|
@ -20,7 +20,6 @@ class NoteRepoResult {
|
||||
|
||||
class GitNoteRepository {
|
||||
final String dirName;
|
||||
final String subDirName;
|
||||
final String baseDirectory;
|
||||
String notesBasePath;
|
||||
final GitRepo _gitRepo;
|
||||
@ -29,14 +28,13 @@ class GitNoteRepository {
|
||||
// The directory should already exist!
|
||||
GitNoteRepository({
|
||||
@required this.dirName,
|
||||
@required this.subDirName,
|
||||
@required this.baseDirectory,
|
||||
}) : _gitRepo = GitRepo(
|
||||
folderName: dirName,
|
||||
authorEmail: Settings.instance.gitAuthorEmail,
|
||||
authorName: Settings.instance.gitAuthor,
|
||||
) {
|
||||
notesBasePath = p.join(baseDirectory, dirName, subDirName);
|
||||
notesBasePath = p.join(baseDirectory, dirName);
|
||||
}
|
||||
|
||||
Future<NoteRepoResult> addNote(Note note) async {
|
||||
|
Reference in New Issue
Block a user