Skip to content

Commit bc29e5f

Browse files
committed
feat(editor): enable partial section rendering via _sections query param
1 parent 5393e4b commit bc29e5f

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

resources/assets/editor/store.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export const useStore = defineStore('main', () => {
151151
const res = await fetch(window.ThemeEditor.route('persistTheme'), {
152152
headers,
153153
method: 'post',
154-
body: JSON.stringify({ ...themeData, updatedSections }),
154+
body: JSON.stringify({ ...themeData, updatedSections: Array.from(updatedSections.keys()) }),
155155
});
156156

157157
if (!skipPreviewRefresh) {

src/Http/Controllers/Admin/ThemeEditorController.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,13 @@ public function persistTheme(Request $request)
5656

5757
$this->themePersister->persist($request->all());
5858

59-
$request = Request::create($request->input('url'), 'GET');
59+
$url = $request->input('url');
60+
61+
if (! empty($sections = $request->input('updatedSections', []))) {
62+
$url .= '&'.http_build_query(['_sections' => implode(',', $sections)]);
63+
}
64+
65+
$request = Request::create($url, 'GET');
6066
$response = app()->handle($request);
6167

6268
return $response->getContent();

src/VisualManager.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace BagistoPlus\Visual;
44

55
use BagistoPlus\Visual\Facades\Sections;
6+
use BagistoPlus\Visual\Facades\ThemeEditor;
67
use BagistoPlus\Visual\Sections\Section;
78
use BagistoPlus\Visual\Sections\SectionInterface;
89
use Illuminate\Support\Facades\Blade;
@@ -98,6 +99,12 @@ public function collectSectionData(string $sectionId, ?string $renderPath = null
9899
*/
99100
public function isSectionEnabled($sectionId): bool
100101
{
102+
if (ThemeEditor::inDesignMode() && request()->has('_sections')) {
103+
$sectionsToRender = explode(',', request()->input('_sections', ''));
104+
105+
return in_array($sectionId, $sectionsToRender);
106+
}
107+
101108
return ! $this->themeDataCollector->getSectionData($sectionId)->disabled;
102109
}
103110

0 commit comments

Comments
 (0)