mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-25 05:07:05 +00:00
feat(sessions): pick existing groups instead of retyping
This commit is contained in:
@@ -314,6 +314,8 @@ fun SessionListScreen(
|
||||
else R.string.sessions_action_change_group
|
||||
),
|
||||
initialName = groupDraft,
|
||||
existingNames = state.rows.mapNotNull { it.summary.metadata?.group?.trim() }
|
||||
.filter { it.isNotEmpty() }.distinct().sorted(),
|
||||
onConfirm = { name ->
|
||||
viewModel.setGroup(row.id, name)
|
||||
groupRow = null
|
||||
@@ -325,6 +327,8 @@ fun SessionListScreen(
|
||||
SessionGroupDialog(
|
||||
title = stringResource(R.string.sessions_group_rename),
|
||||
initialName = groupDraft,
|
||||
existingNames = state.rows.mapNotNull { it.summary.metadata?.group?.trim() }
|
||||
.filter { it.isNotEmpty() }.distinct().sorted(),
|
||||
onConfirm = { name ->
|
||||
viewModel.changeGroup(from, name)
|
||||
groupSectionFrom = null
|
||||
|
||||
+26
-6
@@ -1,6 +1,10 @@
|
||||
package app.hapi.companion.feature.sessions
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.FilterChip
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.Text
|
||||
@@ -11,6 +15,7 @@ import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import app.hapi.companion.R
|
||||
import app.hapi.companion.ui.theme.HapiTheme
|
||||
@@ -56,6 +61,7 @@ fun RenameSessionDialog(
|
||||
fun SessionGroupDialog(
|
||||
title: String,
|
||||
initialName: String,
|
||||
existingNames: List<String> = emptyList(),
|
||||
onConfirm: (String) -> Unit,
|
||||
onDismiss: () -> Unit,
|
||||
) {
|
||||
@@ -64,12 +70,26 @@ fun SessionGroupDialog(
|
||||
onDismissRequest = onDismiss,
|
||||
title = { Text(title) },
|
||||
text = {
|
||||
OutlinedTextField(
|
||||
value = name,
|
||||
onValueChange = { name = it.take(64) },
|
||||
singleLine = true,
|
||||
label = { Text(stringResource(R.string.sessions_group_name)) },
|
||||
)
|
||||
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
OutlinedTextField(
|
||||
value = name,
|
||||
onValueChange = { name = it.take(64) },
|
||||
singleLine = true,
|
||||
label = { Text(stringResource(R.string.sessions_group_name)) },
|
||||
)
|
||||
if (existingNames.isNotEmpty()) {
|
||||
Text(stringResource(R.string.sessions_group_existing))
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
existingNames.forEach { existing ->
|
||||
FilterChip(
|
||||
selected = name == existing,
|
||||
onClick = { name = existing },
|
||||
label = { Text(existing) },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(enabled = name.isNotBlank(), onClick = { onConfirm(name.trim()) }) {
|
||||
|
||||
@@ -277,6 +277,7 @@
|
||||
<string name="sessions_action_save">Сохранить</string>
|
||||
<string name="sessions_group_name">Название группы</string>
|
||||
<string name="sessions_group_rename">Переименовать группу</string>
|
||||
<string name="sessions_group_existing">Существующие группы</string>
|
||||
<string name="sessions_action_join_group">Добавить в группу…</string>
|
||||
<string name="sessions_action_change_group">Изменить группу…</string>
|
||||
<string name="sessions_action_leave_group">Убрать из группы</string>
|
||||
|
||||
@@ -284,6 +284,7 @@
|
||||
<string name="sessions_action_save">保存</string>
|
||||
<string name="sessions_group_name">分组名称</string>
|
||||
<string name="sessions_group_rename">重命名分组</string>
|
||||
<string name="sessions_group_existing">已有分组</string>
|
||||
<string name="sessions_action_join_group">加入分组…</string>
|
||||
<string name="sessions_action_change_group">更改分组…</string>
|
||||
<string name="sessions_action_leave_group">移出分组</string>
|
||||
|
||||
@@ -277,6 +277,7 @@
|
||||
<string name="sessions_action_save">Save</string>
|
||||
<string name="sessions_group_name">Group name</string>
|
||||
<string name="sessions_group_rename">Rename group</string>
|
||||
<string name="sessions_group_existing">Existing groups</string>
|
||||
<string name="sessions_action_join_group">Add to group…</string>
|
||||
<string name="sessions_action_change_group">Change group…</string>
|
||||
<string name="sessions_action_leave_group">Remove from group</string>
|
||||
|
||||
@@ -394,6 +394,15 @@ final class SessionListModel {
|
||||
}
|
||||
}
|
||||
|
||||
/// Distinct existing group names for the quick-pick group menu.
|
||||
var existingGroupNames: [String] {
|
||||
let names = sessionStore.sessions.compactMap { summary -> String? in
|
||||
let name = summary.metadata?.group?.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
return name?.isEmpty == false ? name : nil
|
||||
}
|
||||
return Array(Set(names)).sorted()
|
||||
}
|
||||
|
||||
/// H5-style grouped sections. Search stays flat (the view uses `rows`).
|
||||
var sections: [SessionListSectionUI] {
|
||||
isSearching ? [] : groupedSections(from: rows)
|
||||
|
||||
@@ -38,6 +38,7 @@ struct SessionListView: View {
|
||||
@State private var renameTarget: SessionRowUI?
|
||||
@State private var renameText = ""
|
||||
@State private var deleteTarget: SessionRowUI?
|
||||
@State private var groupPickerTarget: SessionRowUI?
|
||||
@State private var groupRowTarget: SessionRowUI?
|
||||
@State private var groupSectionTarget: SessionListSectionUI?
|
||||
@State private var groupText = ""
|
||||
@@ -135,6 +136,25 @@ struct SessionListView: View {
|
||||
}
|
||||
.disabled(!SessionNameRules.isValid(renameText))
|
||||
}
|
||||
.confirmationDialog(
|
||||
"Choose Group",
|
||||
isPresented: Binding(
|
||||
get: { groupPickerTarget != nil },
|
||||
set: { if !$0 { groupPickerTarget = nil } }
|
||||
),
|
||||
presenting: groupPickerTarget
|
||||
) { row in
|
||||
ForEach(model.existingGroupNames, id: \.self) { name in
|
||||
Button(name) {
|
||||
model.setGroup(sessionId: row.id, group: name)
|
||||
}
|
||||
}
|
||||
Button("New Group…") {
|
||||
groupText = row.summary.metadata?.group ?? ""
|
||||
groupRowTarget = row
|
||||
}
|
||||
Button("Cancel", role: .cancel) {}
|
||||
}
|
||||
.alert(
|
||||
"Change Group",
|
||||
isPresented: Binding(
|
||||
@@ -587,8 +607,7 @@ struct SessionListView: View {
|
||||
Label("Rename…", systemImage: "pencil")
|
||||
}
|
||||
Button {
|
||||
groupText = summary.metadata?.group ?? ""
|
||||
groupRowTarget = row
|
||||
groupPickerTarget = row
|
||||
} label: {
|
||||
Label(summary.metadata?.group == nil ? "Add to Group…" : "Change Group…", systemImage: "rectangle.stack")
|
||||
}
|
||||
|
||||
@@ -7611,6 +7611,40 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"Choose Group" : {
|
||||
"extractionState" : "manual",
|
||||
"localizations" : {
|
||||
"ru" : {
|
||||
"stringUnit" : {
|
||||
"state" : "translated",
|
||||
"value" : "Выберите группу"
|
||||
}
|
||||
},
|
||||
"zh-Hans" : {
|
||||
"stringUnit" : {
|
||||
"state" : "translated",
|
||||
"value" : "选择分组"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"New Group…" : {
|
||||
"extractionState" : "manual",
|
||||
"localizations" : {
|
||||
"ru" : {
|
||||
"stringUnit" : {
|
||||
"state" : "translated",
|
||||
"value" : "Новая группа…"
|
||||
}
|
||||
},
|
||||
"zh-Hans" : {
|
||||
"stringUnit" : {
|
||||
"state" : "translated",
|
||||
"value" : "新建分组…"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"Change Group…" : {
|
||||
"extractionState" : "manual",
|
||||
"localizations" : {
|
||||
|
||||
@@ -9,10 +9,11 @@ import { Button } from '@/components/ui/button'
|
||||
import { useTranslation } from '@/lib/use-translation'
|
||||
|
||||
/** Minimal text-entry dialog for joining, changing, or renaming a group. */
|
||||
export function SessionGroupDialog({ isOpen, onClose, currentName, onSave, isPending }: {
|
||||
export function SessionGroupDialog({ isOpen, onClose, currentName, existingNames = [], onSave, isPending }: {
|
||||
isOpen: boolean
|
||||
onClose: () => void
|
||||
currentName: string
|
||||
existingNames?: string[]
|
||||
onSave: (name: string) => Promise<void>
|
||||
isPending?: boolean
|
||||
}) {
|
||||
@@ -55,11 +56,29 @@ export function SessionGroupDialog({ isOpen, onClose, currentName, onSave, isPen
|
||||
<input
|
||||
id="hapi-group-name"
|
||||
autoFocus
|
||||
list="hapi-group-suggestions"
|
||||
value={draft}
|
||||
maxLength={64}
|
||||
onChange={event => setDraft(event.target.value)}
|
||||
className="w-full rounded-md border border-[var(--app-border)] bg-[var(--app-bg)] px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-[var(--app-link)]"
|
||||
/>
|
||||
<datalist id="hapi-group-suggestions">
|
||||
{existingNames.map(name => <option key={name} value={name} />)}
|
||||
</datalist>
|
||||
{existingNames.length > 0 ? (
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{existingNames.map(name => (
|
||||
<button
|
||||
key={name}
|
||||
type="button"
|
||||
onClick={() => setDraft(name)}
|
||||
className="rounded-full border border-[var(--app-border)] px-2 py-0.5 text-xs text-[var(--app-hint)] hover:bg-[var(--app-subtle-bg)]"
|
||||
>
|
||||
{name}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
{error ? <div role="alert" className="text-xs text-red-600">{error}</div> : null}
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button type="button" variant="secondary" onClick={onClose} disabled={saving}>{t('button.cancel')}</Button>
|
||||
|
||||
@@ -1345,6 +1345,7 @@ const SessionItem = memo(function SessionItem(props: {
|
||||
personalPinned?: boolean
|
||||
onSetPersonalPinned?: (pinned: boolean) => void
|
||||
onSetGroup?: (group: string | null) => Promise<void>
|
||||
existingGroupNames?: string[]
|
||||
onTransferPersonalPinned?: (fromSessionId: string, toSessionId: string) => void
|
||||
projectLabel?: string
|
||||
machineLabel?: string
|
||||
@@ -1370,6 +1371,7 @@ const SessionItem = memo(function SessionItem(props: {
|
||||
personalPinned = false,
|
||||
onSetPersonalPinned,
|
||||
onSetGroup,
|
||||
existingGroupNames = [],
|
||||
onTransferPersonalPinned,
|
||||
projectLabel,
|
||||
machineLabel,
|
||||
@@ -1698,6 +1700,7 @@ const SessionItem = memo(function SessionItem(props: {
|
||||
isOpen={true}
|
||||
onClose={() => setGroupDialogOpen(false)}
|
||||
currentName={s.metadata?.group ?? ''}
|
||||
existingNames={existingGroupNames}
|
||||
onSave={async name => handleSetGroup(name)}
|
||||
isPending={isPending}
|
||||
/>
|
||||
@@ -1830,6 +1833,12 @@ export function SessionList(props: {
|
||||
if (!api) throw new Error('Session unavailable')
|
||||
await api.setSessionGroup(sessionId, group)
|
||||
}
|
||||
const existingGroupNames = useMemo(() => {
|
||||
const names = props.sessions
|
||||
.map(session => session.metadata?.group?.trim())
|
||||
.filter((name): name is string => Boolean(name))
|
||||
return Array.from(new Set(names)).sort()
|
||||
}, [props.sessions])
|
||||
const [groupAction, setGroupAction] = useState<string | null>(null)
|
||||
const [dissolveName, setDissolveName] = useState<string | null>(null)
|
||||
const applyGroupAction = async (name: string) => {
|
||||
@@ -2392,6 +2401,7 @@ export function SessionList(props: {
|
||||
showDetailedStatus={showDetailedStatus}
|
||||
inRunningSection
|
||||
onSetGroup={(group) => setSessionGroup(s.id, group)}
|
||||
existingGroupNames={existingGroupNames}
|
||||
projectLabel={getGroupDisplayName(s.metadata?.worktree?.basePath ?? s.metadata?.path ?? 'Other')}
|
||||
machineLabel={resolveMachineLabel(s.metadata?.machineId ?? null)}
|
||||
shared={sharedSessionIds.has(s.id)}
|
||||
@@ -2461,6 +2471,7 @@ export function SessionList(props: {
|
||||
showDetailedStatus={showDetailedStatus}
|
||||
onSetPersonalPinned={(pinned) => setPersonalPinned(s.id, pinned)}
|
||||
onSetGroup={(group) => setSessionGroup(s.id, group)}
|
||||
existingGroupNames={existingGroupNames}
|
||||
onTransferPersonalPinned={transferPersonalPinned}
|
||||
shared={sharedSessionIds.has(s.id)}
|
||||
contentSnippet={contentSnippetBySessionId.get(s.id)}
|
||||
@@ -3196,6 +3207,7 @@ export function SessionList(props: {
|
||||
personalPinned
|
||||
onSetPersonalPinned={(pinned) => setPersonalPinned(s.id, pinned)}
|
||||
onSetGroup={(group) => setSessionGroup(s.id, group)}
|
||||
existingGroupNames={existingGroupNames}
|
||||
onTransferPersonalPinned={transferPersonalPinned}
|
||||
projectLabel={getGroupDisplayName(s.metadata?.worktree?.basePath ?? s.metadata?.path ?? 'Other')}
|
||||
machineLabel={resolveMachineLabel(s.metadata?.machineId ?? null)}
|
||||
@@ -3253,6 +3265,7 @@ export function SessionList(props: {
|
||||
inRunningSection
|
||||
onSetPersonalPinned={(pinned) => setPersonalPinned(s.id, pinned)}
|
||||
onSetGroup={(group) => setSessionGroup(s.id, group)}
|
||||
existingGroupNames={existingGroupNames}
|
||||
onTransferPersonalPinned={transferPersonalPinned}
|
||||
projectLabel={getGroupDisplayName(s.metadata?.worktree?.basePath ?? s.metadata?.path ?? 'Other')}
|
||||
machineLabel={resolveMachineLabel(s.metadata?.machineId ?? null)}
|
||||
@@ -3297,6 +3310,7 @@ export function SessionList(props: {
|
||||
isOpen={true}
|
||||
onClose={() => setGroupAction(null)}
|
||||
currentName={groupAction}
|
||||
existingNames={existingGroupNames.filter(name => name !== groupAction)}
|
||||
onSave={applyGroupAction}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
Reference in New Issue
Block a user