From 2ce1c4b8e6f2f14041eed465469c571b240b35d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Sun, 12 Nov 2023 00:52:57 +0100 Subject: [PATCH] perf: Already pass board list as initial state MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/Controller/PageController.php | 28 +++++++++---------- src/App.vue | 6 +++- .../navigation/AppNavigationBoardCategory.vue | 3 ++ src/store/main.js | 2 +- tests/unit/controller/PageControllerTest.php | 8 ++++-- 5 files changed, 29 insertions(+), 18 deletions(-) diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index acc9b2a6f..568eb5aad 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -23,12 +23,11 @@ namespace OCA\Deck\Controller; -use OCP\AppFramework\Http\Attribute\NoAdminRequired; -use OCP\AppFramework\Http\Attribute\NoCSRFRequired; use \OCP\AppFramework\Http\RedirectResponse; use OCA\Deck\AppInfo\Application; use OCA\Deck\Db\Acl; use OCA\Deck\Db\CardMapper; +use OCA\Deck\Service\BoardService; use OCA\Deck\Service\CardService; use OCA\Deck\Service\ConfigService; use OCA\Deck\Service\PermissionService; @@ -36,23 +35,24 @@ use OCA\Text\Event\LoadEditor; use OCA\Viewer\Event\LoadViewer; use OCP\AppFramework\Controller; +use OCP\AppFramework\Http\Attribute\NoAdminRequired; +use OCP\AppFramework\Http\Attribute\NoCSRFRequired; use OCP\AppFramework\Http\ContentSecurityPolicy; use OCP\AppFramework\Http\TemplateResponse; +use OCP\AppFramework\Services\IInitialState; use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent as CollaborationResourcesEvent; use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; -use OCP\IInitialStateService; use OCP\IRequest; use OCP\IURLGenerator; class PageController extends Controller { - private IInitialStateService $initialState; - public function __construct( string $AppName, IRequest $request, private PermissionService $permissionService, - IInitialStateService $initialStateService, + private IInitialState $initialState, + private BoardService $boardService, private ConfigService $configService, private IEventDispatcher $eventDispatcher, private CardMapper $cardMapper, @@ -61,8 +61,6 @@ public function __construct( private IConfig $config, ) { parent::__construct($AppName, $request); - - $this->initialState = $initialStateService; } /** @@ -73,9 +71,11 @@ public function __construct( * @NoCSRFRequired */ public function index() { - $this->initialState->provideInitialState(Application::APP_ID, 'maxUploadSize', (int)\OCP\Util::uploadLimit()); - $this->initialState->provideInitialState(Application::APP_ID, 'canCreate', $this->permissionService->canCreate()); - $this->initialState->provideInitialState(Application::APP_ID, 'config', $this->configService->getAll()); + $this->initialState->provideInitialState('maxUploadSize', (int)\OCP\Util::uploadLimit()); + $this->initialState->provideInitialState('canCreate', $this->permissionService->canCreate()); + $this->initialState->provideInitialState('config', $this->configService->getAll()); + + $this->initialState->provideInitialState('initialBoards', $this->boardService->findAll()); $this->eventDispatcher->dispatchTyped(new LoadSidebar()); $this->eventDispatcher->dispatchTyped(new CollaborationResourcesEvent()); @@ -110,19 +110,19 @@ public function indexList(): TemplateResponse { #[NoAdminRequired] #[NoCSRFRequired] public function indexBoard(int $boardId): TemplateResponse { - return $this->index($boardId); + return $this->index(); } #[NoAdminRequired] #[NoCSRFRequired] public function indexBoardDetails(int $boardId): TemplateResponse { - return $this->index($boardId); + return $this->index(); } #[NoAdminRequired] #[NoCSRFRequired] public function indexCard(int $cardId): TemplateResponse { - return $this->index(cardId: $cardId); + return $this->index(); } /** diff --git a/src/App.vue b/src/App.vue index 920bf4a3f..c1fc4eaa8 100644 --- a/src/App.vue +++ b/src/App.vue @@ -49,6 +49,7 @@ import AppNavigation from './components/navigation/AppNavigation.vue' import { NcModal, NcContent, NcAppContent } from '@nextcloud/vue' import { BoardApi } from './services/BoardApi.js' import { emit, subscribe } from '@nextcloud/event-bus' +import { loadState } from '@nextcloud/initial-state' const boardApi = new BoardApi() @@ -108,7 +109,10 @@ export default { }, }, created() { - this.$store.dispatch('loadBoards') + const initialState = loadState('deck', 'initialBoards', null) + if (initialState !== null) { + this.$store.dispatch('loadBoards') + } this.$store.dispatch('loadSharees') }, mounted() { diff --git a/src/components/navigation/AppNavigationBoardCategory.vue b/src/components/navigation/AppNavigationBoardCategory.vue index 805128174..069777f81 100644 --- a/src/components/navigation/AppNavigationBoardCategory.vue +++ b/src/components/navigation/AppNavigationBoardCategory.vue @@ -89,5 +89,8 @@ export default { } }, }, + mounted() { + this.opened = this.boards.length > 0 + }, } diff --git a/src/store/main.js b/src/store/main.js index 3df2e70fa..2692e84d8 100644 --- a/src/store/main.js +++ b/src/store/main.js @@ -66,7 +66,7 @@ export default new Vuex.Store({ sidebarShown: false, currentBoard: null, currentCard: null, - boards: [], + boards: loadState('deck', 'initialBoards', []), sharees: [], assignableUsers: [], boardFilter: BOARD_FILTERS.ALL, diff --git a/tests/unit/controller/PageControllerTest.php b/tests/unit/controller/PageControllerTest.php index f2ed9edfa..f596567a0 100644 --- a/tests/unit/controller/PageControllerTest.php +++ b/tests/unit/controller/PageControllerTest.php @@ -25,12 +25,13 @@ namespace OCA\Deck\Controller; use OCA\Deck\Db\CardMapper; +use OCA\Deck\Service\BoardService; use OCA\Deck\Service\CardService; use OCA\Deck\Service\ConfigService; use OCA\Deck\Service\PermissionService; +use OCP\AppFramework\Services\IInitialState; use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; -use OCP\IInitialStateService; use OCP\IRequest; use OCP\IURLGenerator; use PHPUnit\Framework\TestCase; @@ -40,6 +41,7 @@ class PageControllerTest extends TestCase { private $request; private $permissionService; private $initialState; + private $boardService; private $configService; private $eventDispatcher; /** @@ -61,7 +63,8 @@ public function setUp(): void { $this->request = $this->createMock(IRequest::class); $this->permissionService = $this->createMock(PermissionService::class); $this->configService = $this->createMock(ConfigService::class); - $this->initialState = $this->createMock(IInitialStateService::class); + $this->initialState = $this->createMock(IInitialState::class); + $this->boardService = $this->createMock(BoardService::class); $this->eventDispatcher = $this->createMock(IEventDispatcher::class); $this->cardMapper = $this->createMock(CardMapper::class); $this->urlGenerator = $this->createMock(IURLGenerator::class); @@ -73,6 +76,7 @@ public function setUp(): void { $this->request, $this->permissionService, $this->initialState, + $this->boardService, $this->configService, $this->eventDispatcher, $this->cardMapper,