github.com/alibaba/sealer@v0.8.6-0.20220430115802-37a2bdaa8173/pkg/cloud/dashboard/src/main.rs (about)

     1  // Copyright © 2021 Alibaba Group Holding Ltd.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  pub mod components;
    16  pub mod routes;
    17  pub mod services;
    18  
    19  use yew::prelude::*;
    20  use yew_router::prelude::*;
    21  use crate::components::{header::Header, image_info::ImageDetail};
    22  use crate::routes::{router::AppRoute};
    23  use crate::services::{requests::Images};
    24  
    25  enum Msg {
    26  }
    27  
    28  struct Model {
    29      // `ComponentLink` is like a reference to a component.
    30      // It can be used to send messages to the component
    31      link: ComponentLink<Self>,
    32      value: i64,
    33  }
    34  
    35  impl Component for Model {
    36      type Message = Msg;
    37      type Properties = ();
    38  
    39      fn create(_props: Self::Properties, link: ComponentLink<Self>) -> Self {
    40          Self {
    41              link,
    42              value: 0,
    43          }
    44      }
    45  
    46      fn update(&mut self, msg: Self::Message) -> ShouldRender {
    47          true
    48      }
    49  
    50      fn change(&mut self, _props: Self::Properties) -> ShouldRender {
    51          false
    52      }
    53  
    54      fn view(&self) -> Html {
    55          html! {
    56              <div>
    57                <Header />
    58                <Router<AppRoute> render = Router::render(Self::switch) />
    59              </div>
    60          }
    61      }
    62  }
    63  
    64  impl Model {
    65     fn switch(route: AppRoute) -> Html {
    66          match route {
    67              AppRoute::Images => html! { <Images /> },
    68              AppRoute::ImageDetail(name)=> html! { <ImageDetail image_name=name /> }
    69          }
    70      }
    71  }
    72  
    73  fn main() {
    74      yew::start_app::<Model>();
    75  }