edit_prediction_onboarding_content.rs

 1use std::sync::Arc;
 2
 3use client::{Client, UserStore};
 4use cloud_llm_client::{Plan, PlanV1, 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.user_store.read(cx).plan().is_some_and(|plan| {
40            matches!(plan, Plan::V1(PlanV1::ZedFree) | Plan::V2(PlanV2::ZedFree))
41        });
42
43        let github_copilot = v_flex()
44            .gap_1()
45            .child(Label::new(if self.copilot_is_configured {
46                "Alternatively, you can continue to use GitHub Copilot as that's already set up."
47            } else {
48                "Alternatively, you can use GitHub Copilot as your edit prediction provider."
49            }))
50            .child(
51                Button::new(
52                    "configure-copilot",
53                    if self.copilot_is_configured {
54                        "Use Copilot"
55                    } else {
56                        "Configure Copilot"
57                    },
58                )
59                .full_width()
60                .style(ButtonStyle::Outlined)
61                .on_click({
62                    let callback = self.continue_with_copilot.clone();
63                    move |_, window, cx| callback(window, cx)
64                }),
65            );
66
67        v_flex()
68            .gap_2()
69            .child(ZedAiOnboarding::new(
70                self.client.clone(),
71                &self.user_store,
72                self.continue_with_zed_ai.clone(),
73                cx,
74            ))
75            .when(is_free_plan, |this| {
76                this.child(ui::Divider::horizontal()).child(github_copilot)
77            })
78    }
79}