-
Notifications
You must be signed in to change notification settings - Fork 0
Announcements #110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Announcements #110
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7e8c067
feat(database): setup supabase
bemain 69bbf10
feat(database): create the `announcements` table
bemain 04a49b9
fix(database): reduce modularization of database tables
bemain bfbda8f
feat(announcements): create the `Announcements` class
bemain 8f78543
feat(announcements): create the announcements page and app bar icon
bemain 59864ee
feat(announcements): render `content` as markdown
bemain c1a5e4e
feat(announcements): show latest announcement title as tooltip on sta…
bemain 153709f
fix(announcements): minor fixes
bemain 2ee5da4
fic(announcements): cleanup error message
bemain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import 'package:json_annotation/json_annotation.dart'; | ||
| import 'package:musbx/database/model.dart'; | ||
| import 'package:musbx/utils/utils.dart'; | ||
|
|
||
| part 'announcement.g.dart'; | ||
|
|
||
| @JsonSerializable() | ||
| class Announcement extends Model { | ||
| /// An announcement shown to all users on startup. | ||
| Announcement({ | ||
| super.id, | ||
| super.createdAt, | ||
| required this.title, | ||
| this.content, | ||
| }); | ||
|
|
||
| /// The title of this announcement. | ||
| final String title; | ||
|
|
||
| /// The content of this announcement. | ||
| final String? content; | ||
|
|
||
| static Announcement fromJson(Json json) => _$AnnouncementFromJson(json); | ||
|
|
||
| @override | ||
| Json toJson() => _$AnnouncementToJson(this); | ||
|
|
||
| @override | ||
| String toString() => "Announcement($title)"; | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import 'package:musbx/keys.dart'; | ||
| import 'package:supabase_flutter/supabase_flutter.dart'; | ||
|
|
||
| class Database { | ||
| Database._(); | ||
|
|
||
| /// The supabase client used internally. | ||
| static final SupabaseClient client = Supabase.instance.client; | ||
|
|
||
bemain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /// Whether the database has been [initialize]d. | ||
| static bool isInitialized = false; | ||
|
|
||
| /// Initialize the database connection. | ||
| static Future<void> initialize() async { | ||
| if (isInitialized) return; | ||
|
|
||
| await Supabase.initialize( | ||
| url: supabaseUrl, | ||
| anonKey: supabaseAnonKey, | ||
| ); | ||
|
|
||
| isInitialized = true; | ||
| } | ||
|
|
||
| /// The reference to the 'announcements' table. | ||
| static final SupabaseQueryBuilder announcements = Database.client.from( | ||
| "announcements", | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import 'package:json_annotation/json_annotation.dart'; | ||
| import 'package:musbx/utils/utils.dart'; | ||
| import 'package:uuid/uuid.dart'; | ||
|
|
||
| /// A model with an [id] property that can be serialized to json and stored | ||
| /// on the database. | ||
| abstract class Model { | ||
| Model({ | ||
| String? id, | ||
| DateTime? createdAt, | ||
| }) : id = id ?? Uuid().v4(), | ||
| createdAt = createdAt ?? DateTime.now(); | ||
|
|
||
| /// The unique uuid of this object. | ||
| @JsonKey(required: true) | ||
| final String id; | ||
|
|
||
| /// When this object was created. | ||
| @JsonKey(required: true, name: "created_at") | ||
| final DateTime createdAt; | ||
|
|
||
| /// Serialize this object as json. | ||
| Json toJson(); | ||
|
|
||
| @override | ||
| String toString() => "Model($id)"; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import 'package:material_plus/material_plus.dart'; | ||
| import 'package:musbx/database/announcement.dart'; | ||
| import 'package:musbx/database/database.dart'; | ||
|
|
||
| class Announcements { | ||
| Announcements._(); | ||
|
|
||
| /// The last time the announcements were read. | ||
| static final TransformedPersistentValue<DateTime, String> readAt = | ||
| TransformedPersistentValue( | ||
| "announcements/readAt", | ||
| initialValue: DateTime.now(), | ||
bemain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| from: (value) => DateTime.parse(value), | ||
| to: (value) => value.toIso8601String(), | ||
| ); | ||
|
|
||
| /// Get the latest announcement from the database. | ||
| static Future<Announcement> getLatest() async { | ||
| return await Database.announcements | ||
| .select() | ||
| .order('created_at') | ||
bemain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .limit(1) | ||
| .single() | ||
| .withConverter(Announcement.fromJson); | ||
bemain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /// Get all announcements from the database. | ||
| static Future<List<Announcement>> getAll() async { | ||
| return await Database.announcements | ||
| .select() | ||
| .order('created_at') | ||
| .withConverter( | ||
| (data) => data.map(Announcement.fromJson).toList(), | ||
| ); | ||
| } | ||
|
|
||
| /// Get all announcements from the database that have not been seen before. | ||
| static Future<List<Announcement>> getUnread() async { | ||
| return await Database.announcements | ||
| .select() | ||
| .gt("created_at", readAt.value.toIso8601String()) | ||
| .order('created_at') | ||
| .withConverter( | ||
| (data) => data.map(Announcement.fromJson).toList(), | ||
| ); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.