| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- import SwiftUI
- struct ParaphrasingView: View {
- @StateObject private var viewModel = ParaphrasingViewModel()
- var body: some View {
- GeometryReader { proxy in
- let dynamicHorizontalPadding = min(max(proxy.size.width * 0.045, AppTheme.contentPadding), 52)
- let dynamicBottomPadding = min(max(proxy.size.height * 0.04, 20), 40)
- Group {
- if viewModel.paraphrasedText.isEmpty {
- VStack(alignment: .leading, spacing: 0) {
- header
- .padding(.bottom, 24)
- contentCard
- .frame(maxWidth: .infinity, maxHeight: .infinity)
- if let errorMessage = viewModel.errorMessage {
- Text(errorMessage)
- .font(.system(size: 14))
- .foregroundStyle(.red)
- .padding(.top, 12)
- }
- GradientButton(title: viewModel.isParaphrasing ? "Paraphrasing..." : "Paraphrase") {
- viewModel.paraphrase()
- }
- .disabled(!viewModel.canParaphrase)
- .padding(.top, 16)
- }
- .frame(maxWidth: 1200, maxHeight: .infinity, alignment: .topLeading)
- .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
- .padding(.horizontal, dynamicHorizontalPadding)
- .padding(.top, AppTheme.brandLabelTopInset)
- .padding(.bottom, dynamicBottomPadding)
- } else {
- ScrollView(.vertical, showsIndicators: false) {
- VStack(alignment: .leading, spacing: 0) {
- header
- .padding(.bottom, 24)
- contentCard
- .padding(.bottom, 24)
- outputCard
- .padding(.bottom, 24)
- if let errorMessage = viewModel.errorMessage {
- Text(errorMessage)
- .font(.system(size: 14))
- .foregroundStyle(.red)
- .padding(.bottom, 12)
- }
- GradientButton(title: viewModel.isParaphrasing ? "Paraphrasing..." : "Paraphrase") {
- viewModel.paraphrase()
- }
- .disabled(!viewModel.canParaphrase)
- }
- .frame(maxWidth: 1200, alignment: .topLeading)
- .frame(maxWidth: .infinity, alignment: .topLeading)
- .padding(.horizontal, dynamicHorizontalPadding)
- .padding(.top, AppTheme.brandLabelTopInset)
- .padding(.bottom, dynamicBottomPadding)
- }
- }
- }
- }
- .onChange(of: viewModel.text) { _ in
- viewModel.handleTextChange()
- }
- }
- private var header: some View {
- HStack(alignment: .top) {
- VStack(alignment: .leading, spacing: 8) {
- Text("Paraphrasing")
- .font(.system(size: 30, weight: .bold))
- .foregroundStyle(AppTheme.textPrimary)
- HStack(spacing: 0) {
- Text("Say it ")
- .foregroundStyle(AppTheme.textSecondary)
- Text("differently")
- .fontWeight(.semibold)
- .foregroundStyle(AppTheme.teal)
- Text(". Keep it ")
- .foregroundStyle(AppTheme.textSecondary)
- Text("yours")
- .fontWeight(.semibold)
- .foregroundStyle(AppTheme.teal)
- Text(".")
- .foregroundStyle(AppTheme.textSecondary)
- }
- .font(.system(size: 15))
- }
- Spacer()
- IconButton {
- SettingsGearIcon()
- } action: {}
- .accessibilityLabel("Settings")
- }
- }
- private var contentCard: some View {
- VStack(alignment: .leading, spacing: AppTheme.contentCardSpacing) {
- YourContentHeader()
- VStack(alignment: .leading, spacing: 6) {
- ThinCaretTextEditor(
- text: $viewModel.text,
- placeholder: "Type or paste your text here and press the paraphrase button...",
- maxWords: ParaphrasingViewModel.maxWords,
- onWordLimitReached: viewModel.notifyWordLimitReached
- )
- .font(.system(size: 14))
- .foregroundStyle(AppTheme.textPrimary)
- .frame(maxWidth: .infinity, maxHeight: .infinity)
- .background(Color.white)
- .clipShape(RoundedRectangle(cornerRadius: AppTheme.inputCornerRadius))
- .overlay(
- RoundedRectangle(cornerRadius: AppTheme.inputCornerRadius)
- .stroke(AppTheme.inputBorder, lineWidth: 1)
- )
- Text(viewModel.wordCountLimitLabel)
- .font(.system(size: 11))
- .foregroundStyle(AppTheme.textMuted)
- .frame(maxWidth: .infinity, alignment: .trailing)
- }
- .frame(maxWidth: .infinity, maxHeight: .infinity)
- HStack(spacing: 8) {
- ToolbarButton(title: "Paste Text", iconName: "doc.on.clipboard") {
- viewModel.pasteText()
- }
- ToolbarButton(title: "Upload File", iconName: "square.and.arrow.up") {
- viewModel.uploadFile()
- }
- Spacer()
- ClearButton {
- viewModel.clearText()
- }
- }
- }
- .inputContentCardPadding()
- .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
- .background(AppTheme.cardBackground)
- .clipShape(RoundedRectangle(cornerRadius: AppTheme.cardCornerRadius))
- .overlay(
- RoundedRectangle(cornerRadius: AppTheme.cardCornerRadius)
- .stroke(AppTheme.border, lineWidth: 1)
- )
- .shadow(color: AppTheme.cardShadow, radius: 16, y: 6)
- }
- private var outputCard: some View {
- VStack(alignment: .leading, spacing: 12) {
- HStack {
- Text("Paraphrased Text")
- .font(.system(size: 13, weight: .semibold))
- .foregroundStyle(AppTheme.textPrimary)
- Spacer()
- ToolbarButton(title: "Copy", iconName: "doc.on.doc") {
- viewModel.copyParaphrasedText()
- }
- }
- Text(viewModel.paraphrasedText)
- .font(.system(size: 14))
- .foregroundStyle(AppTheme.textPrimary)
- .frame(maxWidth: .infinity, alignment: .leading)
- .padding(16)
- .background(AppTheme.tealLight.opacity(0.35))
- .clipShape(RoundedRectangle(cornerRadius: AppTheme.inputCornerRadius))
- .overlay(
- RoundedRectangle(cornerRadius: AppTheme.inputCornerRadius)
- .stroke(AppTheme.teal.opacity(0.2), lineWidth: 1)
- )
- }
- .padding(AppTheme.contentCardPadding)
- .background(AppTheme.cardBackground)
- .clipShape(RoundedRectangle(cornerRadius: AppTheme.cardCornerRadius))
- .overlay(
- RoundedRectangle(cornerRadius: AppTheme.cardCornerRadius)
- .stroke(AppTheme.border, lineWidth: 1)
- )
- .shadow(color: AppTheme.cardShadow, radius: 16, y: 6)
- }
- }
|