Widgets work
All checks were successful
Build and Deploy Nuxt / build (push) Successful in 35s

This commit is contained in:
2026-04-30 19:39:53 +02:00
parent ffb23b08eb
commit 139e7d0ef5
16 changed files with 512 additions and 296 deletions

View File

@@ -1,12 +1,41 @@
import Server from './Server';
const SELECTED_CAMPAIGN_KEY = 'selectedCampaignId';
export const useCampaignService = () => {
const Campaign = useState('campaign', () => null)
const SetCampaign = (data) => {
Campaign.value = data;
if (data?._id) {
localStorage.setItem(SELECTED_CAMPAIGN_KEY, data._id);
} else {
localStorage.removeItem(SELECTED_CAMPAIGN_KEY);
}
}
const RestoreCampaign = async () => {
const campaignId = localStorage.getItem(SELECTED_CAMPAIGN_KEY);
if (!campaignId) return false;
try {
const response = await Server().get(`/campaign/retrieve/${campaignId}`);
if (response.data.status !== 'ok') {
SetCampaign(null);
return false;
}
SetCampaign(response.data.campaign);
return true;
} catch (error) {
SetCampaign(null);
return false;
}
}
return {
Campaign,
SetCampaign
SetCampaign,
RestoreCampaign
}
}
}

View File

@@ -0,0 +1,44 @@
import { Marked } from "marked";
const marker = new Marked();
// optional: use a shared marked instance inside renderer
const renderMarkdown = (text) => marker.parse(text);
const WidgetMap = {
test: () => import("~/components/viewer/widgets/TestWidget.vue"),
table: () => import("~/components/viewer/widgets/TableWidget.vue"),
};
const extension = {
name: "something",
level: "block",
tokenizer(src) {
const rule = /^@(\w+)\n([\s\S]+?)\n@end/;
const match = rule.exec(src);
if (!match) return;
return {
type: "something",
raw: match[0],
name: match[1],
text: match[2],
};
},
renderer(token) {
return `<div class="vue-component" data-component="${token.name}" data-content="${token.text}"></div>`;
},
};
marker.use({
extensions: [extension],
});
function ParseMarkdown(source) {
return marker.parse(source || "");
}
export { ParseMarkdown, WidgetMap };

View File

@@ -64,6 +64,7 @@ function LoadUser(){
function LogoutUser(){
localStorage.removeItem("token");
localStorage.removeItem("selectedCampaignId");
UserStatus.value = 0;
}
@@ -77,4 +78,4 @@ export {
HasAdmin,
GetUserSetting,
SetUserSetting
}
}