From a7df45bad58b9d2c85192d9d77e6f71757e7358a Mon Sep 17 00:00:00 2001 From: Szymon Uglis Date: Sat, 27 Nov 2021 22:52:07 +0100 Subject: [PATCH 1/4] Release: 2.0.0-dev.0 --- .github/PULL_REQUEST_TEMPLATE.md | 6 +- .github/workflows/publish.yml | 2 +- .github/workflows/unit_tests.yml | 53 ------- .pubignore | 13 ++ CHANGELOG.md | 6 + analysis_options.yaml | 108 +------------ ...ustom-buttons.dart => custom_buttons.dart} | 24 +-- ...pagination.dart => custom_pagination.dart} | 18 +-- example/example.dart | 8 +- lib/nyxx_pagination.dart | 10 +- lib/src/ComponentPagination.dart | 117 --------------- lib/src/component_pagination.dart | 142 ++++++++++++++++++ lib/src/{IPagination.dart => pagination.dart} | 15 +- pubspec.yaml | 9 +- 14 files changed, 212 insertions(+), 319 deletions(-) create mode 100644 .pubignore rename example/{custom-buttons.dart => custom_buttons.dart} (59%) rename example/{custom-pagination.dart => custom_pagination.dart} (58%) delete mode 100644 lib/src/ComponentPagination.dart create mode 100644 lib/src/component_pagination.dart rename lib/src/{IPagination.dart => pagination.dart} (71%) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index b5ba64c..fa5c6c1 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -4,10 +4,10 @@ Please include a summary of the change and which issue is fixed. Please also inc Use smart commits here to manipulate issues (eg. Fixes #issue) -## Connected issues & potential other potential problems +## Connected issues & other potential problems -If changes are connected to other issues or are affecting code in other parts of framework -(e.g. in main package or any subpackage) make sure to link and describe where and why problem could be present +If changes in PR are connected to other issues or are affecting code in other parts of framework +(e.g. in main package or any other subpackage) make sure to link issue/PR and describe said problem ## Type of change diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index fa3ee14..1a8cce9 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: 'publish nyxx package to pub.dev' + - name: 'publish nyxx_pagination package to pub.dev' id: publish uses: k-paxian/dart-package-publisher@master with: diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index 75a6126..f4dac5f 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -53,56 +53,3 @@ jobs: - name: Format run: dart format --set-exit-if-changed -l 160 ./lib - - tests: - needs: [ format, analyze ] - name: Tests - runs-on: ubuntu-latest - env: - TEST_TOKEN: ${{ secrets.TEST_TOKEN }} - steps: - - name: Cache - uses: actions/cache@v2 - with: - path: ~/.pub_cache - key: ${{ runner.os }} - - - name: Setup Dart Action - uses: dart-lang/setup-dart@v1 - - - name: Install lcov - run: sudo apt-get install -y lcov - - - name: Checkout - uses: actions/checkout@v2.3.4 - - - name: Install dependencies - run: dart pub get - - - name: Unit tests - run: dart run test --coverage="coverage" test/unit/** - - - name: Integration tests - run: dart run test --coverage="coverage" test/integration/** - continue-on-error: true - - - name: Format coverage - run: dart run coverage:format_coverage --lcov --in=coverage --out=coverage/coverage.lcov --packages=.packages --report-on=lib - - - name: Generate coverage - run: genhtml coverage/coverage.lcov -o coverage/coverage_gen - - - name: Extract branch name - shell: bash - run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" - id: extract_branch - - - name: Deploy code coverage - uses: easingthemes/ssh-deploy@v2.1.5 - env: - SSH_PRIVATE_KEY: ${{ secrets.DEPLOY_SSH_SERVER_KEY }} - ARGS: '-rltDzvO --rsync-path="mkdir -p ${{ secrets.DEPLOY_REMOTE_TARGET }}/coverage/nyxx_lavalink/${{ steps.extract_branch.outputs.branch }}/ && rsync"' - SOURCE: "coverage/coverage_gen/" - REMOTE_HOST: ${{ secrets.DEPLOY_REMOTE_HOST }} - REMOTE_USER: ${{ secrets.DEPLOY_REMOTE_USER }} - TARGET: "${{ secrets.DEPLOY_REMOTE_TARGET }}/coverage/nyxx_lavalink/${{ steps.extract_branch.outputs.branch }}/" diff --git a/.pubignore b/.pubignore new file mode 100644 index 0000000..652e425 --- /dev/null +++ b/.pubignore @@ -0,0 +1,13 @@ +# Files and directories created by pub. +.dart_tool/ +.packages + +# Conventional directory for build outputs. +build/ + +# Omit committing pubspec.lock for library packages; see +# https://dart.dev/guides/libraries/private-files#pubspeclock. +pubspec.lock + +.idea/ +.github/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 817713b..615d3e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 2.0.0-dev.0 + +- Bump `nyxx` and `nyxx_interactions` to `3.0.0-dev.0` +- Fixup names of classes +- Migrate to export/import model + ## 1.0.1 - Push fixup diff --git a/analysis_options.yaml b/analysis_options.yaml index 1287252..1f18dab 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,106 +1,8 @@ +include: package:lints/recommended.yaml + analyzer: + exclude: [build/**] + language: + strict-raw-types: true strong-mode: implicit-casts: false -linter: - rules: - - avoid_empty_else - - comment_references - - control_flow_in_finally - - empty_statements - - hash_and_equals - - iterable_contains_unrelated_type - - list_remove_unrelated_type - - avoid_slow_async_io - - cancel_subscriptions - - test_types_in_equals - - throw_in_finally - - valid_regexps - - always_declare_return_types - - annotate_overrides - - avoid_init_to_null - - avoid_return_types_on_setters - - await_only_futures - - camel_case_types - - constant_identifier_names - - empty_constructor_bodies - - library_names - - library_prefixes - - non_constant_identifier_names - - only_throw_errors - - package_api_docs - - package_prefixed_library_names - - prefer_is_not_empty - - slash_for_doc_comments - - type_init_formals - - unnecessary_getters_setters - - package_names - - unnecessary_await_in_return - - use_function_type_syntax_for_parameters - - avoid_returning_null_for_future - - no_duplicate_case_values - - unnecessary_statements - - always_require_non_null_named_parameters - - always_put_required_named_parameters_first - - avoid_catches_without_on_clauses - - avoid_function_literals_in_foreach_calls - - avoid_redundant_argument_values - - avoid_returning_null - - avoid_returning_null_for_void - - avoid_returning_this - - camel_case_extensions - - curly_braces_in_flow_control_structures - - directives_ordering - - empty_catches - - join_return_with_assignment - - leading_newlines_in_multiline_strings - - missing_whitespace_between_adjacent_strings - - no_runtimeType_toString - - null_closures - - omit_local_variable_types - - one_member_abstracts - - prefer_adjacent_string_concatenation - - prefer_collection_literals - - prefer_conditional_assignment - - prefer_const_constructors - - prefer_const_constructors_in_immutables - - prefer_const_declarations - - prefer_const_literals_to_create_immutables - - prefer_constructors_over_static_methods - - prefer_contains - - prefer_double_quotes - - prefer_equal_for_default_values - - prefer_expression_function_bodies - - prefer_final_fields - - prefer_final_in_for_each - - prefer_final_locals - - prefer_for_elements_to_map_fromIterable - - prefer_foreach - - prefer_function_declarations_over_variables - - prefer_generic_function_type_aliases - - prefer_if_elements_to_conditional_expressions - - prefer_if_null_operators - - prefer_initializing_formals - - prefer_inlined_adds - - prefer_int_literals - - prefer_interpolation_to_compose_strings - - prefer_is_empty - - provide_deprecation_message - - prefer_typing_uninitialized_variables - - public_member_api_docs - - unawaited_futures - - unnecessary_brace_in_string_interps - - unnecessary_lambdas - - unnecessary_null_in_if_null_operators - - unnecessary_parenthesis - - unnecessary_raw_strings - - unnecessary_string_escapes - - use_rethrow_when_possible - - use_string_buffers - - void_checks - - use_to_and_as_if_applicable - - sort_pub_dependencies - - prefer_is_not_operator - - prefer_iterable_whereType - - prefer_mixin - - prefer_null_aware_operators - - prefer_spread_collections diff --git a/example/custom-buttons.dart b/example/custom_buttons.dart similarity index 59% rename from example/custom-buttons.dart rename to example/custom_buttons.dart index 9d0713c..37cb2a7 100644 --- a/example/custom-buttons.dart +++ b/example/custom_buttons.dart @@ -1,39 +1,39 @@ import "dart:async"; import "package:nyxx/nyxx.dart"; -import "package:nyxx_interactions/interactions.dart"; +import "package:nyxx_interactions/nyxx_interactions.dart"; import "package:nyxx_pagination/nyxx_pagination.dart"; -class MyCustomPagination extends IComponentPagination { +class MyCustomPagination extends ComponentPaginationAbstract { List get pages => [ "This is first page", "This is second page", ]; @override - int get maxPage => this.pages.length; + int get maxPage => pages.length; - MyCustomPagination(Interactions interactions): super(interactions); + MyCustomPagination(IInteractions interactions): super(interactions); @override ComponentMessageBuilder getMessageBuilderForPage(int page, ComponentMessageBuilder currentBuilder) => currentBuilder..content = pages[page - 1]; @override - FutureOr updatePage(int page, ComponentMessageBuilder currentBuilder, ButtonInteractionEvent target) { - target.respond(this.getMessageBuilderForPage(page, currentBuilder)); + FutureOr updatePage(int page, ComponentMessageBuilder currentBuilder, IButtonInteractionEvent target) { + target.respond(getMessageBuilderForPage(page, currentBuilder)); } @override ComponentMessageBuilder initHook(ComponentMessageBuilder builder) { - final customButtonId = "${this.customPreId}customButton"; + final customButtonId = "${customPreId}customButton"; final customButton = ButtonBuilder("This is custom button", customButtonId, ComponentStyle.success); - this.interactions.onButtonEvent.where((event) => event.interaction.customId == customButtonId).listen((event) async { + interactions.events.onButtonEvent.where((event) => event.interaction.customId == customButtonId).listen((event) async { await event.acknowledge(); await event.respond(MessageBuilder.content("This is custom stuff")); }); - builder.components?.add([ + builder.componentRows?.add([ customButton, ]); @@ -41,16 +41,16 @@ class MyCustomPagination extends IComponentPagination { } } -FutureOr paginationExampleInteraction(SlashCommandInteractionEvent event) { +FutureOr paginationExampleInteraction(ISlashCommandInteractionEvent event) { final pagination = MyCustomPagination(event.interactions); event.respond(pagination.initMessageBuilder()); } void main() { - final bot = Nyxx("", GatewayIntents.allUnprivileged); + final bot = NyxxFactory.createNyxxWebsocket("", GatewayIntents.allUnprivileged); - final interaction = Interactions(bot) + IInteractions.create(WebsocketInteractionBackend(bot)) ..registerSlashCommand(SlashCommandBuilder("paginated", "This is pagination example", [], guild: 302360552993456135.toSnowflake()) ..registerHandler(paginationExampleInteraction)) ..syncOnReady(); diff --git a/example/custom-pagination.dart b/example/custom_pagination.dart similarity index 58% rename from example/custom-pagination.dart rename to example/custom_pagination.dart index b906a74..0fbef5b 100644 --- a/example/custom-pagination.dart +++ b/example/custom_pagination.dart @@ -1,40 +1,40 @@ import "dart:async"; import "package:nyxx/nyxx.dart"; -import "package:nyxx_interactions/interactions.dart"; +import 'package:nyxx_interactions/nyxx_interactions.dart'; import "package:nyxx_pagination/nyxx_pagination.dart"; -class MyCustomPagination extends IComponentPagination { +class MyCustomPagination extends ComponentPaginationAbstract { List get pages => [ "This is first page", "This is second page", ]; @override - int get maxPage => this.pages.length; + int get maxPage => pages.length; - MyCustomPagination(Interactions interactions): super(interactions); + MyCustomPagination(IInteractions interactions): super(interactions); @override ComponentMessageBuilder getMessageBuilderForPage(int page, ComponentMessageBuilder currentBuilder) => currentBuilder..content = pages[page - 1]; @override - FutureOr updatePage(int page, ComponentMessageBuilder currentBuilder, ButtonInteractionEvent target) { - target.respond(this.getMessageBuilderForPage(page, currentBuilder)); + FutureOr updatePage(int page, ComponentMessageBuilder currentBuilder, IButtonInteractionEvent target) { + target.respond(getMessageBuilderForPage(page, currentBuilder)); } } -FutureOr paginationExampleInteraction(SlashCommandInteractionEvent event) { +FutureOr paginationExampleInteraction(ISlashCommandInteractionEvent event) { final pagination = MyCustomPagination(event.interactions); event.respond(pagination.initMessageBuilder()); } void main() { - final bot = Nyxx("", GatewayIntents.allUnprivileged); + final bot = NyxxFactory.createNyxxWebsocket("", GatewayIntents.allUnprivileged); - final interaction = Interactions(bot) + IInteractions.create(WebsocketInteractionBackend(bot)) ..registerSlashCommand(SlashCommandBuilder("paginated", "This is pagination example", [], guild: 302360552993456135.toSnowflake()) ..registerHandler(paginationExampleInteraction)) ..syncOnReady(); diff --git a/example/example.dart b/example/example.dart index 6ff8138..663142e 100644 --- a/example/example.dart +++ b/example/example.dart @@ -1,10 +1,10 @@ import "dart:async"; import "package:nyxx/nyxx.dart"; -import "package:nyxx_interactions/interactions.dart"; +import 'package:nyxx_interactions/nyxx_interactions.dart'; import "package:nyxx_pagination/nyxx_pagination.dart"; -FutureOr paginationExampleInteraction(SlashCommandInteractionEvent event) { +FutureOr paginationExampleInteraction(ISlashCommandInteractionEvent event) { final paginator = EmbedComponentPagination(event.interactions, [ EmbedBuilder()..description = "This is first page", EmbedBuilder()..description = "This is second page", @@ -14,9 +14,9 @@ FutureOr paginationExampleInteraction(SlashCommandInteractionEvent event) } void main() { - final bot = Nyxx("", GatewayIntents.allUnprivileged); + final bot = NyxxFactory.createNyxxWebsocket("", GatewayIntents.allUnprivileged); - final interaction = Interactions(bot) + IInteractions.create(WebsocketInteractionBackend(bot)) ..registerSlashCommand(SlashCommandBuilder("paginated", "This is pagination example", [], guild: 302360552993456135.toSnowflake()) ..registerHandler(paginationExampleInteraction)) ..syncOnReady(); diff --git a/lib/nyxx_pagination.dart b/lib/nyxx_pagination.dart index afd202a..15138f6 100644 --- a/lib/nyxx_pagination.dart +++ b/lib/nyxx_pagination.dart @@ -2,11 +2,5 @@ /// in message. Uses nyxx_interactions to handle pagination in message. library nyxx_pagination; -import "dart:async"; - -import "package:nyxx/nyxx.dart"; -import "package:nyxx_interactions/interactions.dart"; -import "package:random_string/random_string.dart"; - -part "src/IPagination.dart"; -part "src/ComponentPagination.dart"; +export "src/component_pagination.dart"; +export "src/pagination.dart"; diff --git a/lib/src/ComponentPagination.dart b/lib/src/ComponentPagination.dart deleted file mode 100644 index 6a92fc5..0000000 --- a/lib/src/ComponentPagination.dart +++ /dev/null @@ -1,117 +0,0 @@ -part of nyxx_pagination; - -/// Base component paginator. If don't want custom behavior on page update use [ComponentPagination]. -abstract class IComponentPagination extends IPagination { - /// Reference to [Interactions] - final Interactions interactions; - - /// Custom id for this instance of paginator that different paginators could be recognized. - late final String customPreId; - - /// Message builder used to create paginated messages - late ComponentMessageBuilder builder; - - /// Creates new paginator using interactions - IComponentPagination(this.interactions) { - this.customPreId = randomAlpha(10); - } - - /// Inits [ComponentMessageBuilder] with buttons needed for pagination. And hooks needed events. - @override - ComponentMessageBuilder initMessageBuilder() { - final firstPageButtonId = "${customPreId}firstPage"; - final firstPageButton = ButtonBuilder("<<", firstPageButtonId, ComponentStyle.secondary); - interactions.onButtonEvent.where((event) => event.interaction.customId == firstPageButtonId).listen((event) async { - await event.acknowledge(); - - this.onFirstPageButtonClicked(); - updatePage(this.currentPage, this.builder, event); - }); - - final previousPageButtonId = "${customPreId}previousPage"; - final previousPageButton = ButtonBuilder("<", previousPageButtonId, ComponentStyle.secondary); - interactions.onButtonEvent.where((event) => event.interaction.customId == previousPageButtonId).listen((event) async { - await event.acknowledge(); - - this.onPreviousPageButtonClicked(); - updatePage(this.currentPage, this.builder, event); - }); - - final nextPageButtonId = "${customPreId}nextPage"; - final nextPageButton = ButtonBuilder(">", nextPageButtonId, ComponentStyle.secondary); - interactions.onButtonEvent.where((event) => event.interaction.customId == nextPageButtonId).listen((event) async { - await event.acknowledge(); - - this.onNextPageButtonClicked(); - updatePage(this.currentPage, this.builder, event); - }); - - final lastPageButtonId = "${customPreId}lastPage"; - final lastPageButton = ButtonBuilder(">>", lastPageButtonId, ComponentStyle.secondary); - interactions.onButtonEvent.where((event) => event.interaction.customId == lastPageButtonId).listen((event) async { - await event.acknowledge(); - - this.onLastPageButtonClicked(); - updatePage(this.currentPage, this.builder, event); - }); - - final builder = ComponentMessageBuilder() - ..components = [ - [ - firstPageButton, - previousPageButton, - nextPageButton, - lastPageButton, - ] - ]; - - this.builder = this.initHook(builder); - - return this.getMessageBuilderForPage(1, this.builder); - } - - /// Called after initializing basic components. - ComponentMessageBuilder initHook(ComponentMessageBuilder builder) => builder; -} - -/// Base class for custom interaction paginator. -/// [getMessageBuilderForPage] needs to be implemented in order to work. -abstract class ComponentPagination extends IComponentPagination { - /// Creates instance of [ComponentPagination] - ComponentPagination(Interactions interactions) : super(interactions); - - @override - FutureOr updatePage(int page, ComponentMessageBuilder currentBuilder, ButtonInteractionEvent target) { - target.respond(this.getMessageBuilderForPage(page, currentBuilder)); - } -} - -/// Paginator where each page is embed -class EmbedComponentPagination extends ComponentPagination { - @override - int get maxPage => this.embeds.length; - - /// List of embeds to paginate with - final List embeds; - - /// Creates instance of [EmbedComponentPagination] - EmbedComponentPagination(Interactions interactions, this.embeds) : super(interactions); - - @override - ComponentMessageBuilder getMessageBuilderForPage(int page, ComponentMessageBuilder currentBuilder) => currentBuilder..embeds = [embeds[page - 1]]; -} - -/// Paginator where each page is message content -class SimpleComponentPagination extends ComponentPagination { - @override - int get maxPage => this.contentPages.length; - - /// List of string to paginate with - final List contentPages; - - /// Creates instance of [SimpleComponentPagination] - SimpleComponentPagination(Interactions interactions, this.contentPages) : super(interactions); - - @override - ComponentMessageBuilder getMessageBuilderForPage(int page, ComponentMessageBuilder currentBuilder) => currentBuilder..content = contentPages[page - 1]; -} diff --git a/lib/src/component_pagination.dart b/lib/src/component_pagination.dart new file mode 100644 index 0000000..e82f170 --- /dev/null +++ b/lib/src/component_pagination.dart @@ -0,0 +1,142 @@ +import 'dart:async'; + +import 'package:nyxx/nyxx.dart'; +import 'package:nyxx_interactions/nyxx_interactions.dart'; +import 'package:nyxx_pagination/src/pagination.dart'; +import 'package:random_string/random_string.dart'; + +/// Base component paginator. If don't want custom behavior on page update use [ComponentPaginationBase]. +abstract class ComponentPaginationAbstract extends IPagination { + /// Reference to [Interactions] + final IInteractions interactions; + + /// Custom id for this instance of paginator that different paginators could be recognized. + late final String customPreId; + + /// Current page that paginator is on + @override + int currentPage = 1; + + /// Message builder used to create paginated messages + late ComponentMessageBuilder builder; + + /// Creates new paginator using interactions + ComponentPaginationAbstract(this.interactions) { + customPreId = randomAlpha(10); + } + + /// Inits [ComponentMessageBuilder] with buttons needed for pagination. And hooks needed events. + @override + ComponentMessageBuilder initMessageBuilder() { + final firstPageButtonId = "${customPreId}firstPage"; + final firstPageButton = ButtonBuilder("<<", firstPageButtonId, ComponentStyle.secondary); + interactions.events.onButtonEvent.where((event) => event.interaction.customId == firstPageButtonId).listen((event) async { + await event.acknowledge(); + + onFirstPageButtonClicked(); + updatePage(currentPage, this.builder, event); + }); + + final previousPageButtonId = "${customPreId}previousPage"; + final previousPageButton = ButtonBuilder("<", previousPageButtonId, ComponentStyle.secondary); + interactions.events.onButtonEvent.where((event) => event.interaction.customId == previousPageButtonId).listen((event) async { + await event.acknowledge(); + + onPreviousPageButtonClicked(); + updatePage(currentPage, this.builder, event); + }); + + final nextPageButtonId = "${customPreId}nextPage"; + final nextPageButton = ButtonBuilder(">", nextPageButtonId, ComponentStyle.secondary); + interactions.events.onButtonEvent.where((event) => event.interaction.customId == nextPageButtonId).listen((event) async { + await event.acknowledge(); + + onNextPageButtonClicked(); + updatePage(currentPage, this.builder, event); + }); + + final lastPageButtonId = "${customPreId}lastPage"; + final lastPageButton = ButtonBuilder(">>", lastPageButtonId, ComponentStyle.secondary); + interactions.events.onButtonEvent.where((event) => event.interaction.customId == lastPageButtonId).listen((event) async { + await event.acknowledge(); + + onLastPageButtonClicked(); + updatePage(currentPage, this.builder, event); + }); + + final builder = ComponentMessageBuilder() + ..componentRows = [ + [ + firstPageButton, + previousPageButton, + nextPageButton, + lastPageButton, + ] + ]; + + this.builder = initHook(builder); + + return getMessageBuilderForPage(1, this.builder); + } + + /// Called after initializing basic components. + ComponentMessageBuilder initHook(ComponentMessageBuilder builder) => builder; + + /// Invoked on first page button click + @override + void onFirstPageButtonClicked() => currentPage = 1; + + /// Invoked when previous page button is clicked. + @override + void onPreviousPageButtonClicked() => currentPage = (currentPage - 1).clamp(1, maxPage); + + /// Invoked when next page button is clicked. + @override + void onNextPageButtonClicked() => currentPage = (currentPage + 1).clamp(1, maxPage); + + /// Invoked when last page button is clicked. + @override + void onLastPageButtonClicked() => currentPage = maxPage; +} + +/// Base class for custom interaction paginator. +/// [getMessageBuilderForPage] needs to be implemented in order to work. +abstract class ComponentPaginationBase extends ComponentPaginationAbstract { + /// Creates instance of [ComponentPaginationBase] + ComponentPaginationBase(IInteractions interactions) : super(interactions); + + @override + FutureOr updatePage(int page, ComponentMessageBuilder currentBuilder, IButtonInteractionEvent target) { + target.respond(getMessageBuilderForPage(page, currentBuilder)); + } +} + +/// Paginator where each page is embed +class EmbedComponentPagination extends ComponentPaginationBase { + @override + int get maxPage => embeds.length; + + /// List of embeds to paginate with + final List embeds; + + /// Creates instance of [EmbedComponentPagination] + EmbedComponentPagination(IInteractions interactions, this.embeds) : super(interactions); + + @override + ComponentMessageBuilder getMessageBuilderForPage(int page, ComponentMessageBuilder currentBuilder) => currentBuilder..embeds = [embeds[page - 1]]; +} + +/// Paginator where each page is message content +class SimpleComponentPagination extends ComponentPaginationBase { + @override + int get maxPage => contentPages.length; + + /// List of string to paginate with + final List contentPages; + + /// Creates instance of [SimpleComponentPagination] + SimpleComponentPagination(IInteractions interactions, this.contentPages) : super(interactions); + + @override + ComponentMessageBuilder getMessageBuilderForPage(int page, ComponentMessageBuilder currentBuilder) => currentBuilder..content = contentPages[page - 1]; +} diff --git a/lib/src/IPagination.dart b/lib/src/pagination.dart similarity index 71% rename from lib/src/IPagination.dart rename to lib/src/pagination.dart index 57f36e0..d14792b 100644 --- a/lib/src/IPagination.dart +++ b/lib/src/pagination.dart @@ -1,8 +1,11 @@ -part of nyxx_pagination; +import 'dart:async'; +import 'package:nyxx/nyxx.dart'; + +/// Base interface for implementing pagination abstract class IPagination { /// Current page that paginator is on - int currentPage = 1; + int get currentPage; /// Number of pages int get maxPage; @@ -19,14 +22,14 @@ abstract class IPagination { FutureOr updatePage(int page, S currentBuilder, T target); /// Invoked on first page button click - void onFirstPageButtonClicked() => this.currentPage = 1; + void onFirstPageButtonClicked(); /// Invoked when previous page button is clicked. - void onPreviousPageButtonClicked() => this.currentPage = (this.currentPage - 1).clamp(1, this.maxPage); + void onPreviousPageButtonClicked(); /// Invoked when next page button is clicked. - void onNextPageButtonClicked() => this.currentPage = (this.currentPage + 1).clamp(1, this.maxPage); + void onNextPageButtonClicked(); /// Invoked when last page button is clicked. - void onLastPageButtonClicked() => this.currentPage = this.maxPage; + void onLastPageButtonClicked(); } diff --git a/pubspec.yaml b/pubspec.yaml index 1f85f71..90a3d28 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: nyxx_pagination description: Pagination utility for nyxx library -version: 1.0.1 +version: 2.0.0-dev.0 issue_tracker: https://github.com/nyxx-discord/nyxx_pagination/issues repository: https://github.com/nyxx-discord/nyxx_pagination documentation: https://nyxx.l7ssha.xyz/nyxx_pagination @@ -9,6 +9,9 @@ environment: sdk: '>=2.12.0 <3.0.0' dependencies: - nyxx: ^2.0.0 - nyxx_interactions: ^2.0.0 + nyxx: ^3.0.0-dev.0 + nyxx_interactions: ^3.0.0-dev.0 random_string: ^2.3.1 + +dev_dependencies: + lints: ^1.0.1 From b01ac815ac80eac82c3b80f5c95a541fb5bf9e65 Mon Sep 17 00:00:00 2001 From: Szymon Uglis Date: Sun, 28 Nov 2021 15:41:21 +0100 Subject: [PATCH 2/4] Update linter config --- analysis_options.yaml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 1f18dab..53ec678 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,7 +1,12 @@ include: package:lints/recommended.yaml +linter: + rules: + unrelated_type_equality_checks: false + implementation_imports: false + analyzer: - exclude: [build/**] + exclude: [build/**, example/**] language: strict-raw-types: true strong-mode: From 298566e15d30d1b2930d34f92c84f2f7fc353e4c Mon Sep 17 00:00:00 2001 From: Szymon Uglis Date: Thu, 16 Dec 2021 21:57:41 +0100 Subject: [PATCH 3/4] Update CI jobs --- .github/workflows/deploy_docs.yml | 22 +++++++++++++++------- .github/workflows/publish.yml | 15 +++++++++++++-- .github/workflows/unit_tests.yml | 28 ++++++++++++++++------------ 3 files changed, 44 insertions(+), 21 deletions(-) diff --git a/.github/workflows/deploy_docs.yml b/.github/workflows/deploy_docs.yml index 96e7cc8..6dd9a2b 100644 --- a/.github/workflows/deploy_docs.yml +++ b/.github/workflows/deploy_docs.yml @@ -4,30 +4,38 @@ on: push: branches: - dev + - next jobs: deploy-docs: runs-on: ubuntu-latest steps: - - name: Cache - uses: actions/cache@v2 - with: - path: ~/.pub_cache - key: ${{ runner.os }} - - name: Setup Dart Action uses: dart-lang/setup-dart@v1 - name: Checkout uses: actions/checkout@v2.3.4 + - name: Cache + uses: actions/cache@v2 + with: + path: ~/.pub-cache + key: ${{ runner.os }}-pubspec-${{ hashFiles('**/pubspec.lock') }} + restore-keys: | + ${{ runner.os }}-pubspec- + - name: Install dependencies run: dart pub get - name: Generate docs run: dartdoc + - name: Extract branch name + shell: bash + run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" + id: extract_branch + - name: Deploy nyxx dev docs uses: easingthemes/ssh-deploy@v2.1.5 env: @@ -36,4 +44,4 @@ jobs: SOURCE: "doc/api/" REMOTE_HOST: ${{ secrets.DEPLOY_REMOTE_HOST }} REMOTE_USER: ${{ secrets.DEPLOY_REMOTE_USER }} - TARGET: "${{ secrets.DEPLOY_REMOTE_TARGET }}/dartdocs/nyxx_lavalink/" + TARGET: "${{ secrets.DEPLOY_REMOTE_TARGET }}/dartdocs/nyxx_lavalink/${{ steps.extract_branch.outputs.branch }}/" diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 1a8cce9..a20fe92 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -9,8 +9,18 @@ jobs: nyxx_publish: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: 'publish nyxx_pagination package to pub.dev' + - name: Checkout + uses: actions/checkout@v2 + + - name: Cache + uses: actions/cache@v2 + with: + path: ~/.pub-cache + key: ${{ runner.os }}-pubspec-${{ hashFiles('**/pubspec.lock') }} + restore-keys: | + ${{ runner.os }}-pubspec- + + - name: 'publish nyxx package to pub.dev' id: publish uses: k-paxian/dart-package-publisher@master with: @@ -18,6 +28,7 @@ jobs: force: true suppressBuildRunner: true credentialJson: ${{ secrets.CREDENTIAL_JSON }} + - name: 'Commit release tag' if: steps.publish.outputs.success uses: hole19/git-tag-action@master diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index f4dac5f..60cc2df 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -12,18 +12,20 @@ jobs: env: TEST_TOKEN: ${{ secrets.TEST_TOKEN }} steps: - - name: Cache - uses: actions/cache@v2 - with: - path: ~/.pub_cache - key: ${{ runner.os }} - - name: Setup Dart Action uses: dart-lang/setup-dart@v1 - name: Checkout uses: actions/checkout@v2.3.4 + - name: Cache + uses: actions/cache@v2 + with: + path: ~/.pub-cache + key: ${{ runner.os }}-pubspec-${{ hashFiles('**/pubspec.lock') }} + restore-keys: | + ${{ runner.os }}-pubspec- + - name: Install dependencies run: dart pub get @@ -36,18 +38,20 @@ jobs: env: TEST_TOKEN: ${{ secrets.TEST_TOKEN }} steps: - - name: Cache - uses: actions/cache@v2 - with: - path: ~/.pub_cache - key: ${{ runner.os }} - - name: Setup Dart Action uses: dart-lang/setup-dart@v1 - name: Checkout uses: actions/checkout@v2.3.4 + - name: Cache + uses: actions/cache@v2 + with: + path: ~/.pub-cache + key: ${{ runner.os }}-pubspec-${{ hashFiles('**/pubspec.lock') }} + restore-keys: | + ${{ runner.os }}-pubspec- + - name: Install dependencies run: dart pub get From 5abc820c1381c5e6763e6b070a23145819e6c8a5 Mon Sep 17 00:00:00 2001 From: Szymon Uglis Date: Sun, 19 Dec 2021 16:22:05 +0100 Subject: [PATCH 4/4] Release 2.0.0 --- CHANGELOG.md | 7 +++++++ pubspec.yaml | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 615d3e0..64e58b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## 2.0.0 +__19.12.2021__ + +- Bump `nyxx` and `nyxx_interactions` to `3.0.0` +- Fixup names of classes +- Migrate to export/import model + ## 2.0.0-dev.0 - Bump `nyxx` and `nyxx_interactions` to `3.0.0-dev.0` diff --git a/pubspec.yaml b/pubspec.yaml index 90a3d28..dc3b519 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: nyxx_pagination description: Pagination utility for nyxx library -version: 2.0.0-dev.0 +version: 2.0.0 issue_tracker: https://github.com/nyxx-discord/nyxx_pagination/issues repository: https://github.com/nyxx-discord/nyxx_pagination documentation: https://nyxx.l7ssha.xyz/nyxx_pagination @@ -9,8 +9,8 @@ environment: sdk: '>=2.12.0 <3.0.0' dependencies: - nyxx: ^3.0.0-dev.0 - nyxx_interactions: ^3.0.0-dev.0 + nyxx: ^3.0.0 + nyxx_interactions: ^3.0.0 random_string: ^2.3.1 dev_dependencies: