Skip to content

Commit 8498f22

Browse files
leandroBorgesFerreiraLeandro Ferreira
andauthored
Adding explanation to suggestions (#474)
* Adding explanation to suggestions * fixing tab tap * fixing persistence * Translating ai explanation * ktlint * Update DefaultDrawersAndroid.kt * Update DefaultDrawersJs.kt --------- Co-authored-by: Leandro Ferreira <[email protected]>
1 parent d364ebd commit 8498f22

File tree

20 files changed

+3949
-3860
lines changed

20 files changed

+3949
-3860
lines changed

application/core/resources/config/ktlint/baseline.xml

Lines changed: 3789 additions & 3747 deletions
Large diffs are not rendered by default.

application/core/resources/src/commonMain/composeResources/values-en/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,5 @@
122122
<string name="download_model">Download model</string>
123123
<string name="choose_your_model">Write your AI model</string>
124124
<string name="use_offline">Use in offline mode</string>
125+
<string name="ai_explanation">[Tab - accept; Esc - remove]</string>
125126
</resources>

application/core/resources/src/commonMain/composeResources/values-pt/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,5 @@
116116
<string name="download_model">Baixar modelo</string>
117117
<string name="choose_your_model">Escolhe seu modelo de IA</string>
118118
<string name="use_offline">User offline</string>
119+
<string name="ai_explanation">[Tab - aceitar; Esc - remover]</string>
119120
</resources>

application/core/resources/src/commonMain/composeResources/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,5 @@
122122
<string name="download_model">Download model</string>
123123
<string name="choose_your_model">Write your AI model</string>
124124
<string name="use_offline">Use in offline mode</string>
125+
<string name="ai_explanation">[Tab - accept; Esc - remove]</string>
125126
</resources>

application/core/resources/src/commonMain/kotlin/io/writeopia/resources/WrStrings.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import writeopia.application.core.resources.generated.resources.access_ollama_si
77
import writeopia.application.core.resources.generated.resources.account
88
import writeopia.application.core.resources.generated.resources.action_points
99
import writeopia.application.core.resources.generated.resources.actions
10+
import writeopia.application.core.resources.generated.resources.ai_explanation
1011
import writeopia.application.core.resources.generated.resources.are_you_sure
1112
import writeopia.application.core.resources.generated.resources.arrangement
1213
import writeopia.application.core.resources.generated.resources.ask_ai
@@ -403,4 +404,7 @@ object WrStrings {
403404

404405
@Composable
405406
fun useOffline() = stringResource(Res.string.use_offline)
407+
408+
@Composable
409+
fun aiExplanation() = stringResource(Res.string.ai_explanation)
406410
}

application/features/editor/src/commonMain/kotlin/io/writeopia/editor/features/editor/ui/TextEditor.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import androidx.compose.ui.text.font.FontFamily
1616
import io.writeopia.editor.configuration.ui.DrawConfigFactory
1717
import io.writeopia.editor.features.editor.viewmodel.NoteEditorViewModel
1818
import io.writeopia.model.Font
19+
import io.writeopia.resources.WrStrings
1920
import io.writeopia.ui.WriteopiaEditor
2021
import io.writeopia.ui.drawer.factory.DrawersFactory
2122
import io.writeopia.ui.model.DrawStory
@@ -70,6 +71,7 @@ internal fun TextEditor(
7071
defaultBorder = clipShape,
7172
onHeaderClick = noteEditorViewModel::onHeaderClick,
7273
editable = isEditable,
74+
aiExplanation = WrStrings.aiExplanation(),
7375
isDarkTheme = isDarkTheme,
7476
groupsBackgroundColor = Color.Transparent,
7577
drawConfig = DrawConfigFactory.getDrawConfig(),

writeopia/src/commonMain/kotlin/io/writeopia/sdk/manager/WriteopiaManager.kt

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -343,18 +343,21 @@ class WriteopiaManager(
343343

344344
return if (suggestionsResult is ResultData.Complete) {
345345
val suggestions = suggestionsResult.data
346-
suggestions.map { suggestion ->
347-
StoryStep(text = suggestion, type = storyType)
348-
}.fold(storyState()) { state, story ->
349-
addAtPosition(
350-
state,
351-
story.copy(
352-
ephemeral = true,
353-
tags = story.tags + TagInfo(Tag.AI_SUGGESTION)
354-
),
355-
position
356-
)
357-
}.copy(lastEdit = LastEdit.Whole)
346+
suggestions.mapIndexed { i, suggestion ->
347+
val tags = if (i == 0) {
348+
setOf(TagInfo(Tag.AI_SUGGESTION), TagInfo(Tag.FIRST_AI_SUGGESTION))
349+
} else {
350+
setOf(TagInfo(Tag.AI_SUGGESTION))
351+
}
352+
StoryStep(text = suggestion, type = storyType, tags = tags)
353+
}.reversed()
354+
.fold(storyState()) { state, story ->
355+
addAtPosition(
356+
state,
357+
story.copy(ephemeral = true),
358+
position
359+
)
360+
}.copy(lastEdit = LastEdit.Whole)
358361
} else {
359362
storyState()
360363
}

writeopia_models/src/commonMain/kotlin/io/writeopia/sdk/models/story/Tag.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ enum class Tag(val label: String) {
1414
HIGH_LIGHT_BLOCK("HIGH_LIGHT_BLOCK"),
1515
HIDDEN_HX("HIGH_LIGHT_BLOCK"),
1616
COLLAPSED("COLLAPSED"),
17-
AI_SUGGESTION("AI_SUGGESTION");
17+
AI_SUGGESTION("AI_SUGGESTION"),
18+
FIRST_AI_SUGGESTION("FIRST_AI_SUGGESTION");
1819

1920
fun isTitle() =
2021
when (this) {
@@ -23,17 +24,17 @@ enum class Tag(val label: String) {
2324
}
2425

2526
fun hasPosition() = when (this) {
26-
H1, H2, H3, H4, HIDDEN_HX, COLLAPSED, AI_SUGGESTION -> false
27+
H1, H2, H3, H4, HIDDEN_HX, COLLAPSED, AI_SUGGESTION, FIRST_AI_SUGGESTION -> false
2728
HIGH_LIGHT_BLOCK -> true
2829
}
2930

3031
fun isErasable() = when (this) {
31-
H1, H2, H3, H4, HIDDEN_HX, COLLAPSED, AI_SUGGESTION -> false
32+
H1, H2, H3, H4, HIDDEN_HX, COLLAPSED, AI_SUGGESTION, FIRST_AI_SUGGESTION -> false
3233
HIGH_LIGHT_BLOCK -> true
3334
}
3435

3536
fun mustCarryOver() = when (this) {
36-
H1, H2, H3, H4, HIDDEN_HX, COLLAPSED, AI_SUGGESTION -> false
37+
H1, H2, H3, H4, HIDDEN_HX, COLLAPSED, AI_SUGGESTION, FIRST_AI_SUGGESTION -> false
3738
HIGH_LIGHT_BLOCK -> true
3839
}
3940

writeopia_ui/src/androidMain/kotlin/io/writeopia/ui/drawer/factory/DefaultDrawersAndroid.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ object DefaultDrawersAndroid : DrawersFactory {
3030
manager: WriteopiaStateManager,
3131
defaultBorder: Shape,
3232
editable: Boolean,
33+
aiExplanation: String,
3334
isDarkTheme: Boolean,
3435
groupsBackgroundColor: Color,
3536
onHeaderClick: () -> Unit,
@@ -42,7 +43,7 @@ object DefaultDrawersAndroid : DrawersFactory {
4243
val commonDrawers = CommonDrawers.create(
4344
manager,
4445
marginAtBottom = 500.dp,
45-
defaultBorder,
46+
aiExplanation = aiExplanation,
4647
editable,
4748
onHeaderClick,
4849
lineBreakByContent = true,

writeopia_ui/src/commonMain/kotlin/io/writeopia/ui/drawer/content/CheckItemDrawer.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ fun CheckItemDrawerStepPreview() {
130130
TextDrawer(
131131
selectionState = MutableStateFlow(false),
132132
onSelectionLister = {},
133-
isDarkTheme = true
133+
isDarkTheme = true,
134+
aiExplanation = ""
134135
)
135136
}
136137
).Step(

0 commit comments

Comments
 (0)