'use strict'; const { TemplateView, ListView, text } = require('hydrogen-view-sdk'); const ModalView = require('matrix-public-archive-shared/views/ModalView'); const HomeserverSelectionModalContentView = require('./HomeserverSelectionModalContentView'); const MatrixLogoView = require('./MatrixLogoView'); const RoomCardView = require('./RoomCardView'); class RoomDirectoryView extends TemplateView { render(t, vm) { // Make sure we don't overwrite the search input value if someone has typed // before the JavaScript has loaded const searchInputBeforeRendering = document.querySelector('.RoomDirectoryView_searchInput'); if (searchInputBeforeRendering) { const searchInputValueBeforeRendering = searchInputBeforeRendering.value; vm.setSearchTerm(searchInputValueBeforeRendering); } const roomList = new ListView( { className: 'RoomDirectoryView_roomList', list: vm.rooms, parentProvidesUpdates: false, }, (room) => { return new RoomCardView(room); } ); const availableHomeserverOptionElements = vm.availableHomeserverList.map((homeserverName) => { return t.option({ value: homeserverName }, homeserverName); }); const homeserverSelectElement = t.select( { className: 'RoomDirectoryView_homeserverSelector', name: 'homeserver', onInput: (event) => { const optionValue = event.target.value; if (optionValue.startsWith('action:')) { const action = optionValue; vm.onHomeserverSelectionAction(action); // You can't select one of the actions. set the ` is updated when the ViewModel is updated t.mapSideEffect( (vm) => vm.homeserverSelection, (homeserverSelection, oldHomeserverSelection) => { homeserverSelectElement.value = homeserverSelection; const pickedActionOption = homeserverSelection.startsWith('action:'); const isInitialization = oldHomeserverSelection === undefined; if (!pickedActionOption && !isInitialization) { // Submit the page with the new homeserver selection to get results headerForm.submit(); } } ); return t.div( { className: { RoomDirectoryView: true, }, }, [ t.header({ className: 'RoomDirectoryView_header' }, [headerForm]), t.main({ className: 'RoomDirectoryView_mainContent' }, [ t.view(roomList), t.div({ className: 'RoomDirectoryView_paginationButtonCombo' }, [ t.a( { className: 'RoomDirectoryView_paginationButton', href: vm.prevPageUrl }, 'Previous' ), t.a({ className: 'RoomDirectoryView_paginationButton', href: vm.nextPageUrl }, 'Next'), ]), ]), ] ); } } module.exports = RoomDirectoryView;