Snippets Collections
//
//  NotificationViewController.swift
//  Service Provider
//
//  Created by Mac HD on 01/02/2023.
//

import UIKit
import Firebase
import FirebaseFirestore
import FirebaseAuth
import SVProgressHUD

class NotificationViewController: UIViewController {

    @IBOutlet weak var notificationsTableView: UITableView!
    
    @IBOutlet weak var noNotificationsView: UIImageView!
    
    var notifications = [NotificationModel]()
    var arrangedNotifications = [NotificationModel]()
    
    override func viewDidLoad() {
        super.viewDidLoad()

        notificationsTableView.delegate = self
        notificationsTableView.dataSource = self
        
        getNotifications()
    }
    
    func getNotifications() {
        
        let uid = Auth.auth().currentUser?.uid ?? ""
        
        let db = Firestore.firestore()
        db.collection("Notifications")
            .whereField("receiverId", isEqualTo: uid)
            .order(by: "timestamp", descending: true).addSnapshotListener { querySnapShot, error in
                if error != nil {
                    print("Error : ", error as Any)
                    return
                }
                
                self.notifications.removeAll()
                
                var previousDate = ""
                var count = 0
                
                for document in querySnapShot!.documents {
                    
                    count += 1
                    var n = NotificationModel()
                        
                    let date = document.get("timestamp") as? Int ?? 0
                    let d = String(date)
                    let newDate = self.getDateTime(d, "d MMM, yyyy")
                        
                        if newDate != previousDate {
                            let notification = NotificationModel()
                            notification.date = newDate
                           previousDate = newDate
                           self.notifications.append(notification)
                            
                            n.date = ""
                            n.title = document.get("title") as? String ?? ""
                            n.body = document.get("body") as? String ?? ""
                           // notification.time = document.documentID
                            self.notifications.append(n)
                        } else {
                            n.title = document.get("title") as? String ?? ""
                            n.body = document.get("body") as? String ?? ""
                            self.notifications.append(n)
                        }
                }
                if self.notifications.count == 0 {
                    self.noNotificationsView.isHidden = false
                } else {
                    self.noNotificationsView.isHidden = true
                }
                print("an count3 : ", self.notifications.count)
                self.notificationsTableView.reloadData()
                
            }
    }
}


//MARK: - TableView

extension NotificationViewController: UITableViewDelegate, UITableViewDataSource {
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        print("an count453 : ", arrangedNotifications.count)
        return notifications.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let notification = notifications[indexPath.row]
        let notificationDate = notifications[indexPath.row].date
    
        print("n date :", notificationDate)
       
        if notification.date == "" {
            let cell = notificationsTableView.dequeueReusableCell(withIdentifier: "NotificationTableViewCell", for: indexPath) as! NotificationTableViewCell
            cell.selectionStyle = .none
            cell.title.text = notification.title
            cell.bodyLabel.text = notification.body
//            cell.notificationLabel.sizeToFit()
            print("doc34 id : ", notification.date)
            return cell
        } else {
            let cell = notificationsTableView.dequeueReusableCell(withIdentifier: "DateTableViewCell", for: indexPath) as! DateTableViewCell
            cell.dateLabel.text = notification.date
            cell.selectionStyle = .none
            print("date423 : ", notification.date)
            return cell
        }
    }
}
const controller = new AbortController();
const { signal } = controller;

element.addEventListener('click', () => {
  // do whatever 
}, { signal }); 

teardown() {
  super.teardown();
  controller.abort();
}
// show
return Responder::respondValid(
    [
        'Model' => Model::with($relationships)->find($consultTopicId)
    ]
);

// index
return Responder::respondValid(
  	[
      	'MemberProviderConsults' => ConsultLogResource::collection(
        	MemberProviderConsult::with(
            	$this->relations
            )->where('columns', $filter)->orderBy('id', 'desc')->get()
      )
  ]
);

// Store
 $models = Model::create(
    [
        'name' => $request->input('name')
        'description' => $request->input('description', null)
    ]
);

$model->BelongsToManyRelation()->sync($request->input('relatedModelIds'));

return Responder::respondValid(
    [
        'model' => $model
    ]
);

// Update
$model = Model::find($modelId);

if ($request->input('name')) {
    $model->update(
        [
            'name' => $request->input('name')
            'description' => $request->input('description', null)
        ]
    );
}
$model->belongsToManyRelation()->sync($request->input('relatedModelIds'));
$model->questions()->sync($request->input('otherRelatedModelIds'));

$this->updateRequiredQuestions($request, $model->id);

return Responder::respondValid(
    [
        'model' => $model->refresh()->load($this->relations)
    ]
);
star

Fri Jul 07 2023 10:16:45 GMT+0000 (Coordinated Universal Time)

#ios #swift #notification #viewcontroller #controller
star

Thu Mar 02 2023 05:29:10 GMT+0000 (Coordinated Universal Time)

#controller #signal #stop #eventlistener #abort
star

Fri Oct 28 2022 12:53:53 GMT+0000 (Coordinated Universal Time) controller-logic

#php #controller #laravel

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension