1// Copyright © SixtyFPS GmbH <info@slint.dev>
2// SPDX-License-Identifier: MIT
3
4use std::{cell::RefCell, rc::Rc};
5
6use super::traits;
7use crate::mvc;
8
9#[derive(Clone)]
10pub struct MockTaskRepository {
11 tasks: Rc<RefCell<Vec<mvc::TaskModel>>>,
12}
13
14impl MockTaskRepository {
15 pub fn new(tasks: Vec<mvc::TaskModel>) -> Self {
16 Self { tasks: Rc::new(RefCell::new(tasks)) }
17 }
18}
19
20impl traits::TaskRepository for MockTaskRepository {
21 fn task_count(&self) -> usize {
22 self.tasks.borrow().len()
23 }
24
25 fn get_task(&self, index: usize) -> Option<mvc::TaskModel> {
26 self.tasks.borrow().get(index).cloned()
27 }
28
29 fn toggle_done(&self, index: usize) -> bool {
30 if let Some(task) = self.tasks.borrow_mut().get_mut(index) {
31 task.done = !task.done;
32 return true;
33 }
34
35 false
36 }
37
38 fn remove_task(&self, index: usize) -> bool {
39 if index < self.tasks.borrow().len() {
40 self.tasks.borrow_mut().remove(index);
41 return true;
42 }
43
44 false
45 }
46
47 fn push_task(&self, task: mvc::TaskModel) -> bool {
48 self.tasks.borrow_mut().push(task);
49 true
50 }
51}
52