edit_prediction_onboarding_content.rs

 1use std::sync::Arc;
 2
 3use client::{Client, UserStore};
 4use cloud_llm_client::{Plan, PlanV2};
 5use gpui::{Entity, IntoElement, ParentElement};
 6use ui::prelude::*;
 7
 8use crate::ZedAiOnboarding;
 9
10pub struct EditPredictionOnboarding {
11    user_store: Entity<UserStore>,
12    client: Arc<Client>,
13    copilot_is_configured: bool,
14    continue_with_zed_ai: Arc<dyn Fn(&mut Window, &mut App)>,
15    continue_with_copilot: Arc<dyn Fn(&mut Window, &mut App)>,
16}
17
18impl EditPredictionOnboarding {
19    pub fn new(
20        user_store: Entity<UserStore>,
21        client: Arc<Client>,
22        copilot_is_configured: bool,
23        continue_with_zed_ai: Arc<dyn Fn(&mut Window, &mut App)>,
24        continue_with_copilot: Arc<dyn Fn(&mut Window, &mut App)>,
25        _cx: &mut Context<Self>,
26    ) -> Self {
27        Self {
28            user_store,
29            copilot_is_configured,
30            client,
31            continue_with_zed_ai,
32            continue_with_copilot,
33        }
34    }
35}
36
37impl Render for EditPredictionOnboarding {
38    fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
39        let is_free_plan = self
40            .user_store
41            .read(cx)
42            .plan()
43            .is_some_and(|plan| plan == Plan::V2(PlanV2::ZedFree));
44
45        let github_copilot = v_flex()
46            .gap_1()
47            .child(Label::new(if self.copilot_is_configured {
48                "Alternatively, you can continue to use GitHub Copilot as that's already set up."
49            } else {
50                "Alternatively, you can use GitHub Copilot as your edit prediction provider."
51            }))
52            .child(
53                Button::new(
54                    "configure-copilot",
55                    if self.copilot_is_configured {
56                        "Use Copilot"
57                    } else {
58                        "Configure Copilot"
59                    },
60                )
61                .full_width()
62                .style(ButtonStyle::Outlined)
63                .on_click({
64                    let callback = self.continue_with_copilot.clone();
65                    move |_, window, cx| callback(window, cx)
66                }),
67            );
68
69        v_flex()
70            .gap_2()
71            .child(ZedAiOnboarding::new(
72                self.client.clone(),
73                &self.user_store,
74                self.continue_with_zed_ai.clone(),
75                cx,
76            ))
77            .when(is_free_plan, |this| {
78                this.child(ui::Divider::horizontal()).child(github_copilot)
79            })
80    }
81}