Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
alaca committed Feb 4, 2025
1 parent 0926bad commit 48ef08e
Show file tree
Hide file tree
Showing 5 changed files with 192 additions and 1 deletion.
70 changes: 70 additions & 0 deletions src/Campaigns/Blocks/CampaignList/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"$schema": "https://json.schemastore.org/block.json",
"apiVersion": 2,
"name": "givewp/campaign-list-block",
"version": "1.0.0",
"title": "Campaign List Block",
"category": "give",
"description": "Insert an existing campaign into the page.",
"supports": {
"align": [
"wide",
"full",
"left",
"center",
"right"
]
},
"attributes": {
"layout": {
"type": "string",
"default": "full",
"enum": [
"full",
"full"
]
},
"showImage": {
"type": "boolean",
"default": true
},
"showDescription": {
"type": "boolean",
"default": true
},
"showGoal": {
"type": "boolean",
"default": true
},
"sortBy": {
"type": "string",
"default": "date",
"enum": [
"date"
]
},
"orderBy": {
"type": "string",
"default": "desc",
"enum": [
"asc",
"desc"
]
},
"filterBy": {
"type": "array",
"default": []
},
"perPage": {
"type": "number",
"default": "6"
},
"showPagination": {
"type": "boolean",
"default": true
}
},
"textdomain": "give",
"editorScript": "file:../../../../build/campaignListBlock.js",
"render": "file:./render.php"
}
98 changes: 98 additions & 0 deletions src/Campaigns/Blocks/CampaignList/edit.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import {__} from '@wordpress/i18n';
import {InspectorControls, useBlockProps} from '@wordpress/block-editor';
import {BlockEditProps} from '@wordpress/blocks';
import {FormTokenField, PanelBody, SelectControl, ToggleControl} from '@wordpress/components';
import {TokenItem} from "@wordpress/components/build-types/form-token-field/types"
import useCampaigns from "../shared/hooks/useCampaigns";

export default function Edit({attributes, setAttributes}: BlockEditProps<{
layout: string;
showImage: boolean;
showDescription: boolean;
showGoal: boolean;
showPagination: boolean;
sortBy: string;
orderBy: string;
filterBy: (string | TokenItem)[];
perPage: number;
}>) {
const blockProps = useBlockProps();
const {campaigns, hasResolved} = useCampaigns();

return (
<div {...blockProps}>
{hasResolved && (
<InspectorControls>
<PanelBody title={__('Layout', 'give')} initialOpen={true}>
<SelectControl
label={__('Grid', 'give')}
onChange={(layout: string) => setAttributes({layout})}
options={[
{
value: 'full',
label: __('Full', 'give'),
}
]}
/>
</PanelBody>

<PanelBody title={__('Display Elements', 'give')} initialOpen={true}>
<ToggleControl
label={__('Show campaign image', 'give')}
checked={attributes.showImage}
onChange={(showImage) => setAttributes({showImage})}
/>
<ToggleControl
label={__('Show description', 'give')}
checked={attributes.showDescription}
onChange={(showDescription) => setAttributes({showDescription})}
/>
<ToggleControl
label={__('Show goal', 'give')}
checked={attributes.showGoal}
onChange={(showGoal) => setAttributes({showGoal})}
/>
</PanelBody>

<PanelBody title={__('Grid Settings', 'give')} initialOpen={true}>
<SelectControl
label={__('Order By', 'give')}
onChange={(sortBy: string) => setAttributes({sortBy})}
help={__('The order campaigns are displayed in.', 'give')}
options={[
{
value: 'date',
label: __('Date Created', 'give'),
}
]}
/>
<SelectControl
label={__('Order', 'give')}
onChange={(orderBy: string) => setAttributes({orderBy})}
help={__('Choose whether the campaign order ascends or descends.', 'give')}
options={[
{
value: 'desc',
label: __('Descending', 'give'),
},
{
value: 'asc',
label: __('Ascending', 'give'),
}
]}
/>
<FormTokenField
value={attributes.filterBy}
label={__('Filter by Campaign', 'give')}
onChange={(filterBy) => setAttributes({filterBy})}
suggestions={campaigns?.map((campaign) => ({
value: String(campaign.id),
title: campaign.title
}))}
/>
</PanelBody>
</InspectorControls>
)}
</div>
)
}
14 changes: 14 additions & 0 deletions src/Campaigns/Blocks/CampaignList/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import metadata from './block.json';
import Edit from './edit';
import initBlock from '../shared/utils/init-block';
import GiveIcon from '@givewp/components/GiveIcon';

const {name} = metadata;

export {metadata, name};
export const settings = {
edit: Edit,
icon: <GiveIcon color="gray"/>,
};

export const init = () => initBlock({name, metadata, settings});
7 changes: 7 additions & 0 deletions src/Campaigns/Blocks/CampaignList/render.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

/**
* @var array $attributes
*/
print_r($attributes);

4 changes: 3 additions & 1 deletion src/Campaigns/Blocks/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import * as campaignTitleBlock from './CampaignTitleBlock';
import * as campaignCover from './CampaignCover';
import * as campaignDonateButton from './DonateButton';
import * as campaignGoal from './CampaignGoal';
import * as campaignList from './CampaignList';

const getAllBlocks = () => {
return [
campaignTitleBlock,
campaignDonateButton,
campaignGoal,
campaignCover
campaignCover,
campaignList
];
};

Expand Down

0 comments on commit 48ef08e

Please sign in to comment.