'use strict'; const { TemplateView, ListView, text } = require('hydrogen-view-sdk'); const ModalView = require('matrix-viewer-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 RoomDirectoryView_mainContentSection', list: vm.roomCardViewModels, parentProvidesUpdates: false, }, (room) => { return new RoomCardView(room); } ); const homeserverSelectElement = t.select( { className: 'RoomDirectoryView_homeserverSelector', name: 'homeserver', 'data-testid': 'homeserver-select', 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) => { const pickedActionOption = homeserverSelection.startsWith('action:'); const isInitialization = oldHomeserverSelection === undefined; if (!pickedActionOption && !isInitialization) { // Clear the hash out before we submit the form so it doesn't come back from // the dead after the page loads. Normally, the hash would go away in the // modal close callback but this races with it and sometimes we beat it. const path = vm.navigation.pathFrom([]); vm.navigation.applyPath(path); // Set the `