Skip to content

Commit

Permalink
Countdownbar rename and preview working
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenzoJokhan committed Jan 24, 2024
1 parent de16866 commit cb8549a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { useRouter } from 'next/router';
import { useWidgetConfig } from '@/hooks/use-widget-config';
import { useWidgetPreview } from '@/hooks/useWidgetPreview';
import { DateDropdownBarWidgetProps } from '@openstad/date-countdown-bar/src/date-countdown-bar';
import { DateCountdownBarWidgetProps } from '@openstad/date-countdown-bar/src/date-countdown-bar';
import WidgetPreview from '@/components/widget-preview';
import WidgetPublish from '@/components/widget-publish';
import { WithApiUrlProps, withApiUrl } from '@/lib/server-side-props-definition';
Expand All @@ -26,17 +26,17 @@ export default function WidgetDateCountdownBar({

const { data: widget, updateConfig } = useWidgetConfig();
const { previewConfig, updatePreview } =
useWidgetPreview<DateDropdownBarWidgetProps>({
useWidgetPreview<DateCountdownBarWidgetProps>({
projectId,
resourceId: '2',
});

const totalPropPackage = {
...widget?.config,
updateConfig: (config: DateDropdownBarWidgetProps) =>
updateConfig: (config: DateCountdownBarWidgetProps) =>
updateConfig({ ...widget.config, ...config }),

onFieldChanged: (key: keyof DateDropdownBarWidgetProps, value: any) => {
onFieldChanged: (key: keyof DateCountdownBarWidgetProps, value: any) => {
if (previewConfig) {
updatePreview({
...previewConfig,
Expand Down
1 change: 1 addition & 0 deletions apps/api-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"@openstad-headless/comments": "file:../../packages/comments",
"@openstad-headless/likes": "file:../../packages/likes",
"@openstad-headless/resource-overview": "file:../../packages/resource-overview",
"@openstad-headless/date-countdown-bar": "file:../../packages/date-countdown-bar",
"@openstad-headless/resource-detail": "file:../../packages/resource-detail"
},
"devDependencies": {
Expand Down
10 changes: 5 additions & 5 deletions packages/date-countdown-bar/src/date-countdown-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import { differenceInDays, parse } from 'date-fns';
import { zonedTimeToUtc } from 'date-fns-tz';
import { Spacer, Card } from '@openstad-headless/ui/src';

export type DateDropdownBarWidgetProps = {
export type DateCountdownBarWidgetProps = {
beforeText?: string;
afterText?: string;
date: string;
};

function DateDropdownBar({
function DateCountdownBar({
beforeText = '',
date,
afterText = '',
}: DateDropdownBarWidgetProps) {
}: DateCountdownBarWidgetProps) {
const [daysLeft, setDaysLeft] = useState<number>(0);
const urlParams = new URLSearchParams(window.location.search);
const [dateParam] = useState<string>(urlParams.get('date') || date);
Expand Down Expand Up @@ -79,5 +79,5 @@ function DateDropdownBar({
);
}

DateDropdownBar.loadWidget = loadWidget;
export { DateDropdownBar };
DateCountdownBar.loadWidget = loadWidget;
export { DateCountdownBar };
6 changes: 3 additions & 3 deletions packages/date-countdown-bar/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import { DateDropdownBarWidgetProps, DateDropdownBar } from './date-countdown-bar.js';
import { DateCountdownBarWidgetProps, DateCountdownBar } from './date-countdown-bar.js';

const config: DateDropdownBarWidgetProps = {
const config: DateCountdownBarWidgetProps = {
date: '27-01-2024',
beforeText: 'Het is nog niet geweest',
afterText:"Het is al geweest"
};

ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<DateDropdownBar {...config} />
<DateCountdownBar {...config} />
</React.StrictMode>
);

0 comments on commit cb8549a

Please sign in to comment.