Skip to content

Commit

Permalink
Final version of a fully functional todo app
Browse files Browse the repository at this point in the history
  • Loading branch information
dawidurbanski committed Nov 21, 2024
1 parent e279c1d commit c30856a
Show file tree
Hide file tree
Showing 18 changed files with 3,061 additions and 214 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
build
build
.DS_Store
2 changes: 1 addition & 1 deletion includes/admin-menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ function menu() {
}

function admin_page() {
echo '<div id="todo-app"></div>';
echo '<div class="wrap" id="todo-app"></div>';
}
19 changes: 19 additions & 0 deletions includes/admin-styles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace TodoApp;

add_action('admin_enqueue_scripts', __NAMESPACE__ . '\\styles');

function styles() {
$screen = get_current_screen();

if ($screen->id !== 'toplevel_page_todoapp') {
return;
}

wp_enqueue_style(
'wpappointments-admin-css',
TODOAPP_PLUGIN_DIR_URL . '/build/index.css',
array('wp-edit-blocks')
);
}
27 changes: 27 additions & 0 deletions includes/filters.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

add_filter('rest_todoitem_query', function ($args, $request) {
$meta_key = $request->get_param('metaKey');
$meta_value = $request->get_param('metaValue');

if (empty($meta_key)) {
return $args;
}

$args['meta_query'] = [
'relation' => 'OR',
[
'key' => $meta_key,
'value' => $meta_value,
],
];

if ($meta_value === "") {
$args['meta_query'][] = [
'key' => $meta_key,
'compare' => 'NOT EXISTS',
];
}

return $args;
}, 10, 2);
14 changes: 14 additions & 0 deletions includes/init.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

add_action('init', function () {
register_post_type('todoitem', [
'supports' => ['title', 'custom-fields'],
'show_in_rest' => true,
]);

register_post_meta('todoitem', 'completed', [
'single' => true,
'type' => 'boolean',
'show_in_rest' => true,
]);
});
Loading

0 comments on commit c30856a

Please sign in to comment.