Skip to content

Commit

Permalink
Improve entry deprecation notice
Browse files Browse the repository at this point in the history
  • Loading branch information
gabber235 committed Nov 12, 2024
1 parent 5f265b4 commit 729312f
Show file tree
Hide file tree
Showing 54 changed files with 894 additions and 248 deletions.
3 changes: 2 additions & 1 deletion app/lib/app_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import "dart:async";

import "package:auto_route/auto_route.dart";
import "package:flutter/material.dart";
import "package:hooks_riverpod/hooks_riverpod.dart";
import "package:riverpod_annotation/riverpod_annotation.dart";
import "package:typewriter/guard/connected_guard.dart";
import "package:typewriter/models/page.dart";
Expand Down Expand Up @@ -85,7 +86,7 @@ class InvalidatorNavigatorObserver extends NavigatorObserver {

/// Provides the current route data for the given [name].
@Riverpod(keepAlive: true)
RouteData? currentRouteData(CurrentRouteDataRef ref, String path) {
RouteData? currentRouteData(Ref ref, String path) {
final router = ref.watch(appRouter);
return _fetchCurrentRouteData(path, router);
}
Expand Down
2 changes: 1 addition & 1 deletion app/lib/app_router.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions app/lib/models/communicator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ final socketProvider = StateNotifierProvider<SocketNotifier, Socket?>(
class SocketNotifier extends StateNotifier<Socket?> {
SocketNotifier(this.ref) : super(null);

final StateNotifierProviderRef<SocketNotifier, Socket?> ref;
final Ref ref;
bool _disposed = false;

/// When a socket gets disconnected, we want to try to reconnect it.
Expand Down Expand Up @@ -227,13 +227,13 @@ class SocketNotifier extends StateNotifier<Socket?> {
}

@Riverpod(keepAlive: true)
Communicator communicator(CommunicatorRef ref) => Communicator(ref);
Communicator communicator(Ref ref) => Communicator(ref);

@immutable
class Communicator {
const Communicator(this.ref);

final CommunicatorRef ref;
final Ref ref;

Future<void> fetchBook() async {
final socket = ref.read(socketProvider);
Expand Down
2 changes: 1 addition & 1 deletion app/lib/models/communicator.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 11 additions & 3 deletions app/lib/models/entry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,19 @@ String? entryBlueprintId(Ref ref, String entryId) {
return entry?.blueprintId;
}

@riverpod
DeprecatedModifier? entryDeprecated(Ref ref, String entryId) {
final blueprintId = ref.watch(entryBlueprintIdProvider(entryId));
if (blueprintId == null) return null;
final blueprint = ref.watch(entryBlueprintProvider(blueprintId));
if (blueprint == null) return null;
return blueprint.modifiers.whereType<DeprecatedModifier>().firstOrNull;
}

@riverpod
bool isEntryDeprecated(Ref ref, String entryId) {
final entryTags = ref.watch(entryTagsProvider(entryId));
return entryTags.contains("deprecated");
final deprecated = ref.watch(entryDeprecatedProvider(entryId));
return deprecated != null;
}

class EntryDefinition {
Expand Down Expand Up @@ -120,7 +129,6 @@ class Entry {
DataBlueprint? get genericBlueprint {
if (_genericBlueprint != null) return _genericBlueprint;
final genericBlueprint = data["_genericBlueprint"];
print("Generic blueprint: $genericBlueprint");
if (genericBlueprint == null) return null;

if (genericBlueprint is! Map<String, dynamic>) {
Expand Down
133 changes: 132 additions & 1 deletion app/lib/models/entry.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 15 additions & 2 deletions app/lib/models/entry_blueprint.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,12 @@ class EntryBlueprint with _$EntryBlueprint {
required String description,
required String extension,
required ObjectBlueprint dataBlueprint,
@ColorConverter() @Default(Colors.grey) Color color,
@Default(TWIcons.help) String icon,
@Default(<String>[]) List<String> tags,
@Default(null) List<DataBlueprint>? genericConstraints,
@Default(null) DataBlueprint? variableDataBlueprint,
@ColorConverter() @Default(Colors.grey) Color color,
@Default(TWIcons.help) String icon,
@Default([]) List<EntryModifier> modifiers,
}) = _EntryBlueprint;

factory EntryBlueprint.fromJson(Map<String, dynamic> json) =>
Expand Down Expand Up @@ -180,6 +181,18 @@ class Modifier with _$Modifier {
_$ModifierFromJson(json);
}

@Freezed(unionKey: "kind")
class EntryModifier with _$EntryModifier {
const factory EntryModifier() = _EmptyModifier;

const factory EntryModifier.deprecated({
@Default("") String reason,
}) = DeprecatedModifier;

factory EntryModifier.fromJson(Map<String, dynamic> json) =>
_$EntryModifierFromJson(json);
}

const wikiBaseUrl = kDebugMode
? "http://localhost:3000/TypeWriter"
: "https://gabber235.github.io/TypeWriter";
Expand Down
Loading

0 comments on commit 729312f

Please sign in to comment.