Skip to content

Commit f54c20d

Browse files
committed
refactor lib directory
1 parent 2e622f6 commit f54c20d

11 files changed

Lines changed: 779 additions & 992 deletions

README.md

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,47 @@
11
# BookRecs-Front
2-
Book Recommendation App Frontend
32

4-
Installation
5-
1. download flutter in codespace extension pacakge.
6-
2. sh install.sh
7-
Command
8-
3. flutter run -d web-server --web-hostname=0.0.0.0
3+
This Flutter application allows users to:
94

5+
- View current popular books from **Aladin API**
6+
- Search for books by keyword
7+
- Bookmark favorite books
108

9+
## features
1110

12-
For BE
11+
- 🎯 Home screen displaying daily featured books
12+
- 🔍 Book search using GraphQL
13+
- 📚 Bookmark functionality to save your favorite books
14+
- 📱 Responsive and elegant UI using custom themes and styles
15+
16+
## Getting Started
17+
18+
### 🚀 Installation
19+
```bash
20+
git clone <this-repo-url>
21+
cd myapp
22+
flutter pub get
23+
flutter run -d web-server --web-hostname=0.0.0.0
24+
```
25+
26+
📁 `lib/component/graphql_client.dart` line 7
27+
28+
Set up the GraphQL client for querying data from your backend API:
29+
```dart
30+
final HttpLink httpLink = HttpLink(
31+
'https://your-backend-api/graphql', // Replace with your actual backend GraphQL endpoint
32+
);
33+
```
34+
35+
### 🔧 Build Android app
36+
```bash
37+
docker build .
38+
flutter build apk
39+
```
40+
41+
### For Backend Installation
1342
1. git clone https://github.com/BCTP001/be
1443
2. make be/.env and add your aladin api
15-
3. npm run dev
44+
3. sh run.sh
1645

17-
For navigation bar reference
18-
https://github.com/eric-taix/fluid-nav-bar
46+
Implements the fluid navigation bar using `fluid_nav_bar`. For reference, see:
47+
[https://github.com/eric-taix/fluid-nav-bar](https://github.com/eric-taix/fluid-nav-bar)

myapp/lib/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
## Structure
2+
3+
The app is structured into multiple parts:
4+
5+
### 📁 `lib/component`
6+
These files contain supporting classes for content diretory.
7+
### 📁 `lib/content`
8+
This folder holds the widget files that represent different screens used in main.dart.
9+
### 📁 `lib/fluid-nav-bar`
10+
Contains the implementation of the fluid (liquid-style) navigation bar.
11+
### 📁 `main.dart`
12+
The entry point of the application. It runs the app and integrates content and components.

myapp/lib/component/graphql_client.dart

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ import 'package:flutter/material.dart';
33

44
class GraphQLService {
55
static ValueNotifier<GraphQLClient>? _client;
6-
static const String _baseUrl = "https://redesigned-carnival-xp6v4wpj9pw2jv-4000.app.github.dev/";
6+
static const String _baseUrl =
7+
"https://redesigned-carnival-xp6v4wpj9pw2jv-4000.app.github.dev/";
78

89
/// Get or initialize GraphQL client
910
static ValueNotifier<GraphQLClient> getClient() {
1011
if (_client == null) {
1112
// Initialize GraphQL client
1213
final HttpLink httpLink = HttpLink(_baseUrl);
13-
14+
1415
// Create the GraphQL client
1516
_client = ValueNotifier<GraphQLClient>(
1617
GraphQLClient(
@@ -19,16 +20,17 @@ class GraphQLService {
1920
),
2021
);
2122
}
22-
23+
2324
return _client!;
2425
}
2526

2627
/// Sign in with username and password
27-
///
28+
///
2829
/// Returns user data and token on success, null on failure
29-
static Future<Map<String, dynamic>?> signIn(String username, String password) async {
30+
static Future<Map<String, dynamic>?> signIn(
31+
String username, String password) async {
3032
final GraphQLClient client = getClient().value;
31-
33+
3234
const String signInMutation = '''
3335
mutation SignIn(\$username: String!, \$password: String!) {
3436
signIn(username: \$username, password: \$password) {
@@ -40,15 +42,15 @@ class GraphQLService {
4042
}
4143
}
4244
''';
43-
45+
4446
final MutationOptions options = MutationOptions(
4547
document: gql(signInMutation),
4648
variables: {
4749
'username': username,
4850
'password': password,
4951
},
5052
);
51-
53+
5254
try {
5355
final QueryResult result = await client.mutate(options);
5456
if (result.hasException) {
@@ -63,11 +65,12 @@ class GraphQLService {
6365
}
6466

6567
/// Sign up with name, username and password
66-
///
68+
///
6769
/// Returns user data on success, null on failure
68-
static Future<Map<String, dynamic>?> signUp(String name, String username, String password) async {
70+
static Future<Map<String, dynamic>?> signUp(
71+
String name, String username, String password) async {
6972
final GraphQLClient client = getClient().value;
70-
73+
7174
const String signUpMutation = '''
7275
mutation SignUp(\$name: String!, \$username: String!, \$password: String!) {
7376
signUp(name: \$name, username: \$username, password: \$password) {
@@ -77,7 +80,7 @@ class GraphQLService {
7780
}
7881
}
7982
''';
80-
83+
8184
final MutationOptions options = MutationOptions(
8285
document: gql(signUpMutation),
8386
variables: {
@@ -86,7 +89,7 @@ class GraphQLService {
8689
'password': password,
8790
},
8891
);
89-
92+
9093
try {
9194
final QueryResult result = await client.mutate(options);
9295
if (result.hasException) {
@@ -99,23 +102,23 @@ class GraphQLService {
99102
return null;
100103
}
101104
}
102-
105+
103106
/// Sign out current user
104-
///
107+
///
105108
/// Returns success status
106109
static Future<bool> signOut() async {
107110
final GraphQLClient client = getClient().value;
108-
111+
109112
const String signOutMutation = '''
110113
mutation SignOut {
111114
signOut
112115
}
113116
''';
114-
117+
115118
final MutationOptions options = MutationOptions(
116119
document: gql(signOutMutation),
117120
);
118-
121+
119122
try {
120123
final QueryResult result = await client.mutate(options);
121124
if (result.hasException) {
@@ -130,28 +133,26 @@ class GraphQLService {
130133
}
131134

132135
/// Create a new shelf with given name
133-
///
136+
///
134137
/// Returns success message
135138
static Future<Map<String, dynamic>?> createShelf(String shelfName) async {
136139
final GraphQLClient client = getClient().value;
137-
140+
138141
const String createShelfMutation = '''
139142
mutation CreateShelf(\$request: CreateShelfRequest!) {
140143
createShelf(request: \$request) {
141144
msg
142145
}
143146
}
144147
''';
145-
148+
146149
final MutationOptions options = MutationOptions(
147150
document: gql(createShelfMutation),
148151
variables: {
149-
'request': {
150-
"shelfName": shelfName
151-
}
152+
'request': {"shelfName": shelfName}
152153
},
153154
);
154-
155+
155156
try {
156157
final QueryResult result = await client.mutate(options);
157158
if (result.hasException) {
@@ -166,11 +167,12 @@ class GraphQLService {
166167
}
167168

168169
/// Update shelf contents with contain and exclude lists
169-
///
170+
///
170171
/// Returns updated shelf info
171-
static Future<Map<String, dynamic>?> updateShelf(String shelfName, List<String> containList, List<String> excludeList) async {
172+
static Future<Map<String, dynamic>?> updateShelf(String shelfName,
173+
List<String> containList, List<String> excludeList) async {
172174
final GraphQLClient client = getClient().value;
173-
175+
174176
const String updateShelfMutation = '''
175177
mutation UpdateShelf(\$request: UpdateShelfRequest!) {
176178
updateShelf(request: \$request) {
@@ -179,7 +181,7 @@ class GraphQLService {
179181
}
180182
}
181183
''';
182-
184+
183185
final MutationOptions options = MutationOptions(
184186
document: gql(updateShelfMutation),
185187
variables: {
@@ -190,7 +192,7 @@ class GraphQLService {
190192
}
191193
},
192194
);
193-
195+
194196
try {
195197
final QueryResult result = await client.mutate(options);
196198
if (result.hasException) {
@@ -205,11 +207,11 @@ class GraphQLService {
205207
}
206208

207209
/// Get books in a shelf by shelf name
208-
///
210+
///
209211
/// Returns list of books
210212
static Future<List<dynamic>> getBooksInShelf(String shelfName) async {
211213
final GraphQLClient client = getClient().value;
212-
214+
213215
const String getBooksQuery = '''
214216
query GetBooksInShelf(\$request: GetBooksInShelfRequest!) {
215217
getBooksInShelf(request: \$request) {
@@ -234,31 +236,29 @@ class GraphQLService {
234236
}
235237
}
236238
''';
237-
239+
238240
final QueryOptions options = QueryOptions(
239241
document: gql(getBooksQuery),
240242
variables: {
241-
'request': {
242-
"shelfName": shelfName
243-
}
243+
'request': {"shelfName": shelfName}
244244
},
245245
);
246-
246+
247247
try {
248248
final QueryResult result = await client.query(options);
249249
if (result.hasException) {
250250
debugPrint('GraphQL Error: ${result.exception.toString()}');
251251
return [];
252252
}
253-
253+
254254
if (result.data != null && result.data!['getBooksInShelf'] != null) {
255255
return result.data!['getBooksInShelf'] as List<dynamic>;
256256
}
257-
257+
258258
return [];
259259
} catch (e) {
260260
debugPrint('Error in getBooksInShelf: $e');
261261
return [];
262262
}
263263
}
264-
}
264+
}

0 commit comments

Comments
 (0)