Skip to content

Commit 3329cb7

Browse files
committed
revert the ui for search
1 parent 32307e9 commit 3329cb7

File tree

1 file changed

+12
-102
lines changed

1 file changed

+12
-102
lines changed

api/ui.py

Lines changed: 12 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -927,20 +927,6 @@ async def serve_ui():
927927
renderFileField(fieldArea, '');
928928
} else if (selectedType === 'search') {
929929
renderSearchField(fieldArea, data.pecha_title || '', data.pecha_text_id || '');
930-
// If editing and has content, create a mock search result with the content
931-
if (data.content && data.pecha_title && data.pecha_text_id) {
932-
const contentDataScript = document.createElement('script');
933-
contentDataScript.type = 'application/json';
934-
contentDataScript.className = 'ctx-pecha-content-data';
935-
// Create a single item array with the content
936-
contentDataScript.textContent = JSON.stringify([{
937-
id: data.pecha_text_id,
938-
content: data.content,
939-
type: 'text',
940-
source: 'pecha'
941-
}]);
942-
fieldArea.appendChild(contentDataScript);
943-
}
944930
}
945931
}
946932
@@ -1090,74 +1076,27 @@ async def serve_ui():
10901076
const titleText = el.textContent.trim();
10911077
const displayTitle = titleText.length > 80 ? titleText.slice(0,80) + '...' : titleText;
10921078
1093-
// Show loading state
1094-
el.innerHTML = '<span class="spinner" style="width:12px;height:12px;border-width:2px"></span> Loading content...';
1095-
el.style.pointerEvents = 'none';
1079+
titleInput.value = displayTitle;
1080+
idInput.value = id;
10961081
1097-
try {
1098-
// Call the search endpoint to fetch content
1099-
const r = await fetch(API_BASE + '/search/' + encodeURIComponent(id));
1100-
if (!r.ok) throw new Error('Failed to fetch content');
1101-
const searchData = await r.json();
1102-
1103-
// Store both the title and the fetched content
1104-
titleInput.value = displayTitle;
1105-
idInput.value = id;
1106-
1107-
// Store content data as JSON in a script tag to avoid HTML escaping issues
1108-
let contentScript = fieldArea.querySelector('.ctx-pecha-content-data');
1109-
if (!contentScript) {
1110-
contentScript = document.createElement('script');
1111-
contentScript.type = 'application/json';
1112-
contentScript.className = 'ctx-pecha-content-data';
1113-
fieldArea.appendChild(contentScript);
1114-
}
1115-
contentScript.textContent = JSON.stringify(searchData || []);
1116-
1117-
resultsDiv.style.display = 'none';
1118-
tagsDiv.innerHTML = '';
1119-
addPechaTag(tagsDiv, fieldArea, displayTitle, id, searchData);
1120-
1121-
toast('Content loaded successfully! (' + (searchData?.length || 0) + ' items)', 'success');
1122-
} catch(e) {
1123-
toast('Error loading content: ' + e.message, 'error');
1124-
el.innerHTML = displayTitle;
1125-
el.style.pointerEvents = '';
1126-
}
1082+
resultsDiv.style.display = 'none';
1083+
tagsDiv.innerHTML = '';
1084+
addPechaTag(tagsDiv, fieldArea, displayTitle, id, null);
1085+
1086+
toast('Pecha text selected!', 'success');
11271087
}
11281088
11291089
function addPechaTag(tagsDiv, fieldArea, title, id, searchData) {
11301090
const tag = document.createElement('div');
11311091
tag.style.cssText = 'margin-top:8px';
11321092
1133-
// Add main tag
11341093
tag.innerHTML = `
11351094
<div class="pecha-tag">
11361095
<span class="pecha-tag-text">${esc(title)}</span>
11371096
<button class="pecha-tag-remove" onclick="removePechaTag(this)">&times;</button>
11381097
</div>
11391098
`;
11401099
1141-
// If we have search data, show the content items
1142-
if (searchData && searchData.length > 0) {
1143-
const contentList = document.createElement('div');
1144-
contentList.style.cssText = 'margin-top:8px;display:flex;flex-direction:column;gap:8px';
1145-
1146-
searchData.forEach((item, idx) => {
1147-
const contentPreview = (item.content || '').substring(0, 150);
1148-
const itemDiv = document.createElement('div');
1149-
itemDiv.style.cssText = 'padding:8px 10px;background:var(--bg-input);border:1px solid var(--border);border-radius:var(--radius-xs);font-size:12px';
1150-
itemDiv.innerHTML = `
1151-
<div style="color:var(--text-secondary);line-height:1.5">
1152-
${esc(contentPreview)}${contentPreview.length >= 150 ? '...' : ''}
1153-
</div>
1154-
`;
1155-
contentList.appendChild(itemDiv);
1156-
});
1157-
1158-
tag.appendChild(contentList);
1159-
}
1160-
11611100
tagsDiv.appendChild(tag);
11621101
}
11631102
@@ -1167,12 +1106,6 @@ async def serve_ui():
11671106
fieldArea.querySelector('.ctx-pecha-title').value = '';
11681107
fieldArea.querySelector('.ctx-pecha-text-id').value = '';
11691108
1170-
// Remove the content data script if it exists
1171-
const contentDataScript = fieldArea.querySelector('.ctx-pecha-content-data');
1172-
if (contentDataScript) {
1173-
contentDataScript.remove();
1174-
}
1175-
11761109
// Clear the pecha tags div
11771110
const tagsDiv = fieldArea.querySelector('.pecha-tags');
11781111
if (tagsDiv) {
@@ -1191,36 +1124,13 @@ async def serve_ui():
11911124
} else if (type === 'search') {
11921125
const pecha_title = e.querySelector('.ctx-pecha-title')?.value.trim();
11931126
const pecha_text_id = e.querySelector('.ctx-pecha-text-id')?.value.trim();
1194-
const contentDataScript = e.querySelector('.ctx-pecha-content-data');
11951127
11961128
if (pecha_title && pecha_text_id) {
1197-
// Parse the stored JSON data
1198-
let searchData = [];
1199-
if (contentDataScript) {
1200-
try {
1201-
searchData = JSON.parse(contentDataScript.textContent || '[]');
1202-
} catch(err) {
1203-
console.error('Failed to parse search data', err);
1204-
}
1205-
}
1206-
1207-
// Create separate context entries for each search result
1208-
if (searchData.length > 0) {
1209-
searchData.forEach(item => {
1210-
contexts.push({
1211-
content: item.content || null,
1212-
pecha_title: pecha_title,
1213-
pecha_text_id: pecha_text_id
1214-
});
1215-
});
1216-
} else {
1217-
// No content loaded yet, just store the metadata
1218-
contexts.push({
1219-
content: null,
1220-
pecha_title: pecha_title,
1221-
pecha_text_id: pecha_text_id
1222-
});
1223-
}
1129+
contexts.push({
1130+
content: null,
1131+
pecha_title: pecha_title,
1132+
pecha_text_id: pecha_text_id
1133+
});
12241134
}
12251135
}
12261136
// Note: 'file' type contexts are handled separately via getFilesFromForm()

0 commit comments

Comments
 (0)