Fix some lifetime annotation issues

This commit is contained in:
Jeremy Wall 2022-12-27 22:08:50 -06:00
parent 69dc4b99cf
commit fbb4e4ceeb
5 changed files with 12 additions and 9 deletions

View File

@ -164,7 +164,7 @@ pub fn Viewer<'ctx, G: Html>(cx: Scope<'ctx>, props: RecipeComponentProps<'ctx>)
let RecipeComponentProps { recipe_id, sh } = props;
let state = app_state::State::get_from_context(cx);
let view = create_signal(cx, View::empty());
let recipe_signal = sh.get_selector(cx, |state| {
let recipe_signal = sh.get_selector(cx, move |state| {
if let Some(recipe) = state.get().recipes.get(&recipe_id) {
let title = recipe.title.clone();
let desc = recipe.desc.clone().unwrap_or_else(|| String::new());

View File

@ -11,14 +11,17 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use crate::{app_state, components::recipe::Viewer};
use crate::{
app_state::{self, StateHandler},
components::recipe::Viewer,
};
use sycamore::prelude::*;
use tracing::{debug, instrument};
#[instrument]
#[instrument(skip_all)]
#[component]
pub fn RecipeList<G: Html>(cx: Scope) -> View<G> {
pub fn RecipeList<'ctx, G: Html>(cx: Scope<'ctx>, sh: StateHandler<'ctx>) -> View<G> {
let state = app_state::State::get_from_context(cx);
let menu_list = create_memo(cx, move || state.get_menu_list());
view! {cx,
@ -26,10 +29,10 @@ pub fn RecipeList<G: Html>(cx: Scope) -> View<G> {
div() {
Indexed(
iterable=menu_list,
view= |cx, (id, _count)| {
view= move |cx, (id, _count)| {
debug!(id=%id, "Rendering recipe");
view ! {cx,
Viewer(id)
Viewer(recipe_id=id, sh=sh)
hr()
}
}

View File

@ -21,6 +21,6 @@ pub fn CookPage<'ctx, G: Html>(cx: Scope<'ctx>, sh: StateHandler<'ctx>) -> View<
view! {cx,
PlanningPage(
selected=Some("Cook".to_owned()),
) { RecipeList() }
) { RecipeList(sh) }
}
}

View File

@ -19,7 +19,7 @@ use tracing::instrument;
#[instrument(skip_all, fields(recipe=props.recipe))]
#[component()]
pub fn RecipeEditPage<G: Html>(cx: Scope, props: RecipePageProps) -> View<G> {
pub fn RecipeEditPage<'ctx, G: Html>(cx: Scope<'ctx>, props: RecipePageProps<'ctx>) -> View<G> {
let RecipePageProps { recipe, sh } = props;
view! {cx,
RecipePage(

View File

@ -20,7 +20,7 @@ use super::{RecipePage, RecipePageProps};
#[instrument(skip_all, fields(recipe=props.recipe))]
#[component()]
pub fn RecipeViewPage<G: Html>(cx: Scope, props: RecipePageProps) -> View<G> {
pub fn RecipeViewPage<'ctx, G: Html>(cx: Scope<'ctx>, props: RecipePageProps<'ctx>) -> View<G> {
let RecipePageProps { recipe, sh } = props;
view! {cx,
RecipePage(