Skip to content

A self-hosted media server and file management system

new toasts

aminnausincc76065e0bc8
diff --git a/public/js/auth.js b/public/js/auth.js
deleted file mode 100644
index 15532222..00000000
--- a/public/js/auth.js
+++ /dev/null
@@ -1,55 +0,0 @@
-document.addEventListener("DOMContentLoaded", function(event) {
- fetch(`/sanctum/csrf-cookie`, {
- method: 'get'
- }).catch((error) => {
- console.log(error);
- });
-});
-
-function login(){
- const remember_me = document.getElementById("remember_me");
- fetch(`/api/login`, {
- method: 'post',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
- body: JSON.stringify({
- 'email': $('#email').val(),
- 'password': $('#password').val(), //'123456789!aB'
- 'remember_me': remember_me.checked
- })
- }).then((response) =>
- response.json()
- ).then((json) => {
- console.log(json);
- if(json.success){
- localStorage.setItem('auth-token', json.data.token)
- toastr['info'](localStorage.getItem('auth-token'));
- window.location.href = '/';
- }
- }).catch((error) => {
- console.log(error);
- });
-}
-
-function logout(){
- const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
-
- fetch(`/logout`, {
- method: 'post',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json',
- 'X-CSRF-TOKEN': csrfToken
- }
- }).then(response =>
- response.json()
- ).then(json => {
- console.log(json);
- localStorage.removeItem('auth-token');
- if(json.success == true) window.location.href = "/";
- }).catch((error) => {
- console.log(error);
- });
-}
\ No newline at end of file
diff --git a/public/js/history.js b/public/js/history.js
deleted file mode 100644
index 897994a6..00000000
--- a/public/js/history.js
+++ /dev/null
@@ -1,281 +0,0 @@
-var token = ''
-var folderData = [];
-
-/*
- Video Retrieval Structure :
-
- Requires :
- - directory
- - folder name
-
- Path :
- -> DOMContentLoaded
- -> loadCategoryFolders() - get folders in directory and then
- -> parseFolders() - create ui components for each folder from last request
- -> loadVideosAndParse() - parses the given folder name to a folder from last request and creates a datatable to correspond to it
- - gets videos that have given folder's id and creates ui components (table rows) and then
- -> initVideos() - initialises ui functionality for each video row
-
- Video History Structure :
-
-
-*/
-
-document.addEventListener("DOMContentLoaded", function(event) {
- try {
- loadHistory();
-
- if(document.getElementById('dark-mode-toggle')){
- document.getElementById('dark-mode-toggle').addEventListener('click', () => { toggleDarkMode(); });
- toggleDarkMode();
- }
- } catch (error) {
- toastr['error']('Unable to load data.');
- console.log(error);
- return;
- }
-
- //#region UI Navigation
-
- $("#user-header").on('click', function(){
- document.querySelector("#user-dropdown").classList.toggle("hidden");
- });
-
- $("#btn-nav-back").on('click', function(){
- cycleSideBar("folders");
- });
-
- window.addEventListener('click', function(e){
- try {
- let dropdown = this.document.querySelector("#user-dropdown")
- if (!this.document.querySelector("#user-options").contains(e.target)){
- dropdown.classList.add("hidden");
- }
- } catch (error) {
- console.log(error);
- }
- });
-
- //#endregion
-});
-
-//#region UI Navigation
-
-function showLogin(){
- window.location.href = "/login";
-}
-
-function showSignup(){
- window.location.href = "/register";
-}
-
-//#endregion
-
-async function loadHistory(){
- if(!user) return;
- const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
- fetch(`/api/records`, {
- method: 'get',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json',
- 'X-CSRF-TOKEN': csrfToken
- }
- }).then((response) =>
- response.json()
- ).then((json) => {
- // console.log(json);
- if(json.success == true){
- parseHistory(json.data);
- console.log('loading history');
- }
- }).catch((error) => {
- console.log(error);
- });
-}
-
-async function addToHistory(id){
- if(!user) return;
- const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
-
- fetch(`/api/records`, {
- method: 'post',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json',
- 'X-CSRF-TOKEN': csrfToken
- },
- body: JSON.stringify({
- 'video_id': id,
- })
- }).then((response) =>
- response.json()
- ).then((json) => {
- // console.log(json);
- if(json.success == true) {
- // toastr['success']('Added to history!');
- // loadHistory();
- parseHistory([json.data], false);
- };
- }).catch((error) => {
- console.log(error);
- });
-}
-
-function parseHistory(data, empty = true) {
- let destination = '#content-history';
- let recordTemplate = function(videoName, folderName, timeSpan, date, recordID) {
- return `
- <div class="flex gap-12 group cursor-default">
- <div class="flex rounded-xl items-center justify-center dark:bg-neutral-800 dark:hover:bg-neutral-700 hover:bg-slate-200 bg-slate-100 dark:text-white shadow p-3 w-full group flex-grow cursor-pointer">
- <div class="w-full flex-wrap divide-y divide-gray-300">
- <section class="flex justify-between items-baseline w-full">
- <h2 class="text-xl text-left truncate">${videoName}</h2>
- <h2 class="text-xl text-right truncate">${date}</h2>
- </section>
- <aside class="flex justify-between items-center w-full pt-1">
- <h3 class="text-lg text-left text-neutral-500 truncate">${folderName}</h3>
- <h3 class="text-lg text-right text-neutral-500 text-nowrap line-clamp-1 truncate">${timeSpan}</h3>
- <span class="hidden flex space-x-1">
- <button class="hover:bg-orange-500 hover:stroke-none border-orange-500 border-2 rounded shadow px-2">Watch</button>
- <svg xmlns="https://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
- <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 13.5 12 21m0 0-7.5-7.5M12 21V3" />
- </svg>
- </span>
- </aside>
- </div>
- </div>
- <div class="aspect-square rounded-full items-center justify-center group-hover:visible invisible flex">
- <button class="record-delete w-full p-3 items-center justify-center rounded-xl bg-red-700 hover:bg-red-600" data-id='${recordID}'>
- Delete
- </button>
- </div>
- </div>
- `
- }
-
- //if(empty) $(destination).empty();
-
- for (let recordCount = 0; recordCount < data.length; recordCount++) {
- const recordID = data[recordCount].id;
- const videoName = data[recordCount].relationships.video_name;
- const folderName = data[recordCount].relationships.folder_name;
- const categoryName = data[recordCount].relationships.category_name;
- const rawDate = (new Date(data[recordCount].attributes.created_at.replace(' ', 'T')));
- const rawAge = Date.now() - rawDate.getTime();
-
- const weeks = Math.round(rawAge / (1000 * 3600 * 24 * 7));
- const days = Math.round(rawAge / (1000 * 3600 * 24));
- const hours = Math.round(rawAge / (1000 * 3600));
- const minutes = Math.round(rawAge / (1000 * 60));
- const seconds = Math.round(rawAge / (1000));
-
- const timeSpan = weeks > 0 ? `${weeks} week${weeks > 1 ? 's' : ''} ago` : days > 0 ? `${days} day${days > 1 ? 's' : ''} ago` : hours > 0 ? `${hours} hour${hours > 1 ? 's' : ''} ago` : minutes > 0 ? `${minutes}m ago` : `${seconds}s ago`
-
- let recordElement = recordTemplate(videoName, folderName, timeSpan, `${rawDate.toLocaleDateString([], {year: "numeric", month: '2-digit', day: '2-digit', hour: '2-digit', hour12:false, minute:'2-digit'})}`, recordID);
- if(empty) $(destination).append(recordElement)
- else {
- $(destination).children().last().remove();
- $(destination).prepend(recordElement);
- }
-
- $(destination).children().last().children().first().on('click', () => {
- window.location.href = `/${categoryName}/${folderName}`
- })
- }
-
- $(".record-delete").off('click').on('click.delete', function(){
- const id = parseInt($(this).data('id'));
- const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
-
- if(isNaN(id)){
- toastr.error(`Invalid Record ID... ${$(this).data('id')}`);
- return;
- }
-
- fetch(`/api/records/${id}`, {
- method: 'delete',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json',
- 'X-CSRF-TOKEN': csrfToken
- }
- }).then((response) =>
- response.json()
- ).then((json) => {
- if(json.success == true) {
- toastr.success('Record deleted!');
- $(this).parent().parent().remove();
- };
- }).catch((error) => {
- console.log(error);
- toastr.error('Unable to delete record.');
- });
- })
-}
-
-function toggleDarkMode(){
- let rootHTML = document.querySelector('html');
- try {
- let darkModeToggle = document.getElementById('dark-mode-toggle');
- let currElemClass = !darkModeToggle.checked ? 'light-mode' : 'dark-mode';
- let nextElemClass = !darkModeToggle.checked ? 'dark-mode' : 'light-mode';
- let currBtnClass = !darkModeToggle.checked ? 'btn-light' : 'btn-dark';
- let nextBtnClass = !darkModeToggle.checked ? 'btn-dark' : 'btn-light';
-
- darkModeToggle.checked ? rootHTML.classList.remove("dark", "tw-dark") : rootHTML.classList.add("dark", "tw-dark");
-
- let elems = document.querySelectorAll('.' + currElemClass);
- let btns = document.querySelectorAll('.' + currBtnClass);
-
- for (let el of elems) {
- el.classList.replace(currElemClass, nextElemClass);
- }
-
- for (let btn of btns) {
- btn.classList.replace(currBtnClass, nextBtnClass);
- }
- } catch (error) {
- let darkModeToggle = {checked: true}
- let currElemClass = !darkModeToggle.checked ? 'light-mode' : 'dark-mode';
- let nextElemClass = !darkModeToggle.checked ? 'dark-mode' : 'light-mode';
- let currBtnClass = !darkModeToggle.checked ? 'btn-light' : 'btn-dark';
- let nextBtnClass = !darkModeToggle.checked ? 'btn-dark' : 'btn-light';
-
- darkModeToggle.checked ? rootHTML.classList.remove("dark", "tw-dark") : rootHTML.classList.add("dark", "tw-dark");
-
- let elems = document.querySelectorAll('.' + currElemClass);
- let btns = document.querySelectorAll('.' + currBtnClass);
-
- for (let el of elems) {
- el.classList.replace(currElemClass, nextElemClass);
- }
-
- for (let btn of btns) {
- btn.classList.replace(currBtnClass, nextBtnClass);
- }
- }
-}
-
-function getDarkModeSettings(){
- try {
- let darkModeToggle = document.getElementById('dark-mode-toggle');
- let currElemClass = darkModeToggle.checked ? 'light-mode' : 'dark-mode';
- let currBtnClass = darkModeToggle.checked ? 'btn-light' : 'btn-dark';
-
- return {
- elementClass: currElemClass,
- btnClass: currBtnClass
- }
- } catch (error) {
-
- let darkModeToggle = true;
- let currElemClass = darkModeToggle ? 'light-mode' : 'dark-mode';
- let currBtnClass = darkModeToggle ? 'btn-light' : 'btn-dark';
-
- return {
- elementClass: currElemClass,
- btnClass: currBtnClass
- }
- }
-}
\ No newline at end of file
diff --git a/public/js/main-old.js b/public/js/main-old.js
deleted file mode 100644
index eb73cca8..00000000
--- a/public/js/main-old.js
+++ /dev/null
@@ -1,88 +0,0 @@
-async function loadVideos(){
- const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
- const dir = stateVideoDirectory ?? 'anime';
-
- fetch('/ajax/generateDir', {
- method: 'post',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json',
- 'X-CSRF-TOKEN': csrfToken
- },
- body: JSON.stringify({
- dir:dir
- })
- }).then((response) =>
- response.json()
- ).then((json) => {
- console.log(json);
- if(json.success == false){
- toastr["error"](`The directory '${dir}' does not exist.`, "Invalid Category");
- return;
- }
- parseVideos(json.result);
- }).catch((error) => {
- console.log(error);
- });
-}
-
-function parseVideos(data){
- // const dataContainer = document.getElementById('dataContainer');
- const darkModeSettings = getDarkModeSettings();
-
- var folderTemplate = function(folderName, folderCount, fileElements) {
- return `
- <div class="col-sm-12">
- <div class="folder-header row mb-4">
- <h4 class="col-sm-8 col-lg-10 ps-0 text-center text-sm-start"> ${folderName} </h4>
- <button class="col-sm-4 col-lg-2 btn ${darkModeSettings.btnClass} folder-toggle" id="dataTable-${folderCount}-collapse-toggle" type="button" data-bs-toggle="collapse" data-bs-target="#dataTable-${folderCount}-collapse">
- <i class="bi bi-list"></i>
- Show Folder
- </button>
- </div>
- <div class="collapse show" id="dataTable-${folderCount}-collapse" data-state="0">
- <table class="vid-table hover stripe" id="dataTable-${folderCount}" data-folder="${folderName}">
- <thead>
- <tr>
- <th>Title</th>
- <!-- <th>Length</th> -->
- <th>Date</th>
- </tr>
- </thead>
- <tbody>
- ${fileElements}
- </tbody>
- </table>
- </div>
- </div>
- <hr>
- `
- }
- var videoTemplate = function(fileArray){
- let fileName = fileArray['name'].substring(1);
- let title = fileArray['title'];
- let date = fileArray['date'];
- let formattedDate = fileArray['formattedDate'];
- return `
- <tr>
- <td class="vid-row" data-col="col-title" value="${fileName}">${title}</td>
- <!-- <td class="vid-row" data-col="col-length" value="0">Unimplemented</td> -->
- <td class="vid-row" data-col="col-date" value="${date}">${formattedDate}</td>
- </tr>
- `
- }
-
- // console.log(data.length);
-
- for (let folderCount = 0; folderCount < data.length; folderCount++) {
- const folderName = data[folderCount]['name'];
- const files = data[folderCount]['files'];
-
- let fileElements = files.map(videoTemplate);
- let folderElement = folderTemplate(folderName, folderCount, fileElements.toString().replaceAll(',',''));
- $('#dataContainer').append(folderElement);
- }
-
- initVideos();
-}
-
diff --git a/public/js/main.js b/public/js/main.js
deleted file mode 100644
index 2e9205d9..00000000
--- a/public/js/main.js
+++ /dev/null
@@ -1,519 +0,0 @@
-var token = ''
-var folderData = [];
-
-/*
- Video Retrieval Structure :
-
- Requires :
- - directory
- - folder name
-
- Path :
- -> DOMContentLoaded
- -> loadCategoryFolders() - get folders in directory and then
- -> parseFolders() - create ui components for each folder from last request
- -> loadVideosAndParse() - parses the given folder name to a folder from last request and creates a datatable to correspond to it
- - gets videos that have given folder's id and creates ui components (table rows) and then
- -> initVideos() - initialises ui functionality for each video row
-
- Video History Structure :
-
-
-*/
-
-document.addEventListener("DOMContentLoaded", function(event) {
- try {
- if(stateFolder === null | stateFolder === undefined) { loadVideos(); }
- else { loadCategoryFolders(); }
-
- if(document.getElementById('dark-mode-toggle')){
- document.getElementById('dark-mode-toggle').addEventListener('click', () => { toggleDarkMode(); });
- toggleDarkMode();
- }
- } catch (error) {
- toastr['error']('Unable to load data.');
- console.log(error);
- return;
- }
-
- //#region UI Navigation
-
- // $("#user-header").on('click', function(){
- // document.querySelector("#user-dropdown").classList.toggle("hidden");
- // });
-
- $("#btn-nav-folders").on('click', function(){
- cycleSideBar("folders");
- });
-
- $("#btn-nav-history").on('click', function(){
- cycleSideBar("history");
- });
-
- // window.addEventListener('click', function(e){
- // try {
- // let dropdown = this.document.querySelector("#user-dropdown")
- // if (!this.document.querySelector("#user-options").contains(e.target)){
- // dropdown.classList.add("hidden");
- // }
- // } catch (error) {
- // console.log(error);
- // }
- // });
-
- //#endregion
-});
-
-function reload(newFolderID, newFolderName){
- stateFolder = {id: newFolderID, name: newFolderName};
- window.history.pushState({dir: stateDirectory.name, folder: stateFolder.name},`${stateDirectory.name} - ${stateFolder.name}`, `/${stateDirectory.name}/${stateFolder.name}`);
- loadVideosAndParse(folderData);
-}
-
-//#region UI Navigation
-
-function showLogin(){
- window.location.href = "/login";
-}
-
-function showSignup(){
- window.location.href = "/register";
-}
-
-function showHistory(){
- document.querySelector("#content-video").classList.add("hidden");
- document.querySelector("#content-history").classList.remove("hidden");
-}
-
-function showContent(){
- document.querySelector("#content-history").classList.add("hidden");
- document.querySelector("#content-video").classList.remove("hidden");
-}
-
-function cycleSideBar(state){
- let listCard = document.querySelector('#list-card');
- if(state === "folders" && document.querySelector("#list-content-folders").classList.contains('hidden')){
- document.querySelector("#list-card").classList.remove("invisible");
- document.querySelector("#list-content-folders").classList.toggle("hidden");
- document.querySelector("#list-content-history").classList.add("hidden");
- $('#sidebar-title').text('Folders');
- listCard.scrollIntoView({behavior: "smooth"});
- }
- else if(state === "history" && document.querySelector("#list-content-history").classList.contains('hidden')){
- document.querySelector("#list-card").classList.remove("invisible");
- document.querySelector("#list-content-history").classList.toggle("hidden");
- document.querySelector("#list-content-folders").classList.add("hidden");
- $('#sidebar-title').text('History');
- listCard.scrollIntoView({behavior: "smooth"});
- loadHistory();
- }
- else{
- document.querySelector("#list-card").classList.add("invisible");
- document.querySelector("#list-content-history").classList.add("hidden");
- document.querySelector("#list-content-folders").classList.add("hidden");
- document.getElementById('root').scrollIntoView({behavior: "smooth"});
- }
-}
-
-//#endregion
-
-async function loadHistory(limit = 10){
- if(!user) return;
- const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
- fetch(`/api/records?limit=${limit}`, {
- method: 'get',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json',
- 'X-CSRF-TOKEN': csrfToken
- }
- }).then((response) =>
- response.json()
- ).then((json) => {
- // console.log(json);
- if(json.success == true){
- parseHistory(json.data);
- console.log('loading history');
- }
- }).catch((error) => {
- console.log(error);
- });
-}
-
-async function addToHistory(id){
- if(!user) return;
- const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
-
- fetch(`/api/records`, {
- method: 'post',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json',
- 'X-CSRF-TOKEN': csrfToken
- },
- body: JSON.stringify({
- 'video_id': id,
- })
- }).then((response) =>
- response.json()
- ).then((json) => {
- // console.log(json);
- if(json.success == true) {
- // toastr['success']('Added to history!');
- // loadHistory();
- parseHistory([json.data], 10, false);
- };
- }).catch((error) => {
- console.log(error);
- });
-}
-
-function parseHistory(data, count = 10, empty = true) {
- let destination = '#list-content-history';
- let recordTemplate = function(videoName, folderName, timeSpan) {
- return `
- <div class="flex flex-wrap rounded-xl dark:bg-neutral-800 dark:hover:bg-neutral-700 hover:bg-slate-200 bg-slate-100 dark:text-white shadow p-[3%] w-full divide-y divide-gray-300 group flex-grow">
- <section class="flex justify-between items-baseline w-full">
- <h2 class="text-xl text-left truncate">${videoName}</h2>
- </section>
- <aside class="flex justify-between items-center w-full pt-1">
- <h3 class="text-lg text-left text-neutral-500 truncate">${folderName}</h2>
- <h3 class="text-lg text-right text-neutral-500 text-nowrap line-clamp-1 truncate">${timeSpan}</h3>
- <span class="hidden flex space-x-1">
- <button class="hover:bg-orange-500 hover:stroke-none border-orange-500 border-2 rounded shadow px-2">Watch</button>
- <svg xmlns="https://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
- <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 13.5 12 21m0 0-7.5-7.5M12 21V3" />
- </svg>
- </span>
- </aside>
- </div>
- `
- }
-
- if(empty) $(destination).empty();
-
- for (let recordCount = 0; recordCount < Math.min(data.length, count); recordCount++) {
- const videoName = data[recordCount].relationships.video_name;
- const folderName = data[recordCount].relationships.folder_name;
- const rawDate = (new Date(data[recordCount].attributes.created_at.replace(' ', 'T')));
- const rawAge = Date.now() - rawDate.getTime();
-
- const weeks = Math.round(rawAge / (1000 * 3600 * 24 * 7));
- const days = Math.round(rawAge / (1000 * 3600 * 24));
- const hours = Math.round(rawAge / (1000 * 3600));
- const minutes = Math.round(rawAge / (1000 * 60));
- const seconds = Math.round(rawAge / (1000));
-
- const timeSpan = weeks > 0 ? `${weeks} week${weeks > 1 ? 's' : ''} ago` : days > 0 ? `${days} day${days > 1 ? 's' : ''} ago` : hours > 0 ? `${hours} hour${hours > 1 ? 's' : ''} ago` : minutes > 0 ? `${minutes}m ago` : `${seconds}s ago`
-
- let recordElement = recordTemplate(videoName, folderName, timeSpan);
- if(empty) $(destination).append(recordElement)
- else {
- $(destination).children().last().remove();
- $(destination).prepend(recordElement);
- }
- }
-}
-
-async function loadCategoryFolders(){
- const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
-
- if(isNaN(parseInt(stateDirectory.id))){
- toastr["error"](`An invalid category "${stateDirectory.name}" was provided in the URL.`, "Invalid Category");
- return;
- }
-
- fetch(`/api/folders`, {
- method: 'post',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json',
- 'X-CSRF-TOKEN': csrfToken
- },
- body: JSON.stringify({
- category_id:stateDirectory.id
- })
- }).then((response) =>
- response.json()
- ).then((json) => {
- // console.log(json);
- if(json.success == false){
- toastr["error"](`The directory '${stateDirectory.name}' does not exist.`, "Invalid Category");
- return;
- }
-
- folderData = json.data;
- parseFolders(folderData);
- loadVideosAndParse(folderData);
- }).catch((error) => {
- console.log(error);
- });
-}
-
-async function parseFolders(data){
-
- var folderTemplate = function(folder_id, folder_name, file_count) {
- return `
- <div class="p-2 flex flex-wrap rounded-xl bg-neutral-100 dark:bg-neutral-800 dark:text-white shadow-md w-full divide-y divide-gray-300 group">
- <section class="flex justify-between items-baseline w-full">
- <h2 class="text-xl truncate">${folder_name}</h2>
- </section>
- <aside class="flex justify-between items-center w-full pt-1">
- <h3 class="text-lg text-left text-neutral-500">${file_count} Episode${file_count > 1 ? 's' : ''}</h2>
- <button class="hidden group-hover:flex space-x-1 folder-link" data-id="${folder_id}" data-name="${folder_name}">
- <span class="flex hover:bg-orange-500 hover:stroke-none border-orange-500 border-2 rounded shadow px-2 space-x-1">
- Watch
- </span>
- <svg xmlns="https://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
- <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 13.5 12 21m0 0-7.5-7.5M12 21V3" />
- </svg>
- </button>
- </aside>
- </div>
- `
- }
-
- data.forEach(folder => {
- const folder_id = folder.id;
- const folder_name = folder.attributes.name;
- const file_count = folder.attributes.file_count;
-
- let folder_element = folderTemplate(folder_id, folder_name, file_count);
-
- $('#list-content-folders').append(folder_element);
- });
-
- $('.folder-link').on('mousedown', (e) => {
- let name = e.currentTarget.dataset.name;
- let id = e.currentTarget.dataset.id;
-
- if(e.which != 2) reload(id, name);
- else window.open(`/${stateDirectory.name}/${name}`, '_blank');
- });
-}
-
-async function loadVideosAndParse(data){
- const darkModeSettings = getDarkModeSettings();
- const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
- var folderTemplate = function(folderName, folderCount, fileElements) {
- return `
- <div class="w-full">
- <div class="folder-header flex justify-center sm:justify-start">
- <h2 class="text-2xl py-4 hidden"> ${folderName} </h2>
- <h2 class="text-2xl py-4">Episodes</h2>
- </div>
- <div class="" id="dataTable-${folderCount}-collapse" data-state="1">
- <table class="vid-table hover stripe" id="dataTable-${folderCount}" data-folder="${folderName}">
- <thead>
- <tr>
- <th>Title</th>
- <!-- <th>Length</th> -->
- <th>Date</th>
- </tr>
- </thead>
- <tbody>
- ${fileElements}
- </tbody>
- </table>
- </div>
- </div>
- <hr>
- `
- }
- var videoTemplate = function(fileArray){
- const filePath = fileArray.attributes.path;
- const title = fileArray.attributes.name;
- const rawDate = new Date(fileArray.attributes.date + ' GMT');
- const id = fileArray.id;
- const filePrefix = '../';
- return `
- <tr class="vid-row" data-id="${id}" data-path="${filePrefix}${filePath}">
- <td class="vid-row-title line-clamp-1">${title}</td>
- <td class="vid-row-date truncate overflow-hidden">${(rawDate.toLocaleString([], {year: 'numeric', month: '2-digit', day:'2-digit', hour:'2-digit', minute:'2-digit', hour12: true})).toLocaleUpperCase().replaceAll('.','')}</td>
- </tr>
- `
- }
-
- // parse the user provided folder name into an actual folder in the directory and get id if id not present
- if(isNaN(parseInt(stateFolder.id))){
- if(stateFolder.name === null | stateFolder.name === undefined) {
- toastr["error"](`An invalid folder name "${stateFolder.name}" was provided in the URL.`, "Invalid Folder");
- return;
- }
-
- let res = data.find(folder => folder.attributes["name"].toLowerCase().localeCompare(stateFolder.name.toLowerCase()) == 0);
- if(!res){
- toastr["error"](`An invalid folder name "${stateFolder.name}" was provided in the URL.`, "Invalid Folder");
- return;
- }
- stateFolder = {id: res["id"], name: res.attributes["name"]};
- }
-
- fetch(`/api/videos`, {
- method: 'post',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json',
- 'X-CSRF-TOKEN': csrfToken
- },
- body: JSON.stringify({
- folder_id: stateFolder.id
- })
- }).then((response) =>
- response.json()
- ).then((json) => {
- if(json.success == false){
- toastr["error"](`The folder '${stateFolder.name}' does not exist.`, "Invalid folder");
- return;
- }
-
- const files = json.data;
- // console.log(files);
- let fileElements = files.map(videoTemplate);
- let folderElement = folderTemplate(stateFolder.name, 0, fileElements.toString().replaceAll(',',''));
- $('#dataContainer').empty();
- $('#dataContainer').append(folderElement);
-
- initVideos();
- }).catch((error) => {
- console.log(error);
- });
-}
-
-function initVideos(){
- let pastFirst = false;
- $('.vid-row').off('click').on('click', function(){
- let file = $(this).data('path');
- let id = $(this).data('id');
- let vidSource = document.getElementById('vid-source');
- let root = document.getElementById('root');
- let folder = $(this).closest('table');
- // let lastID = $(vidSource).data('vid-id');
-
- // if(!isNaN(parseInt(lastID))){
- // addToHistory(lastID);
- // }
-
- try {
- vidSource.pause();
- } catch (error) {
- console.log('No video running. Cannot pause.')
- }
-
- $(vidSource).attr('src', file);
- // $(vidSource).data('vid-id', id);
- vidSource.load();
- if(pastFirst){
- vidSource.play();
- }
- else pastFirst = true;
-
- try {
- root.scrollIntoView();
- } catch (error) {
- console.log(error);
- console.log(root);
- console.log(document.getElementById('root'));
- }
-
- $('#mp4-title').text($(this).find(".vid-row-title").text());
- $('#mp4-title-folder').text($(folder).data('folder'));
- $('#folder-thumbnail').attr('src', `${stateThumbnailDir}${stateFolder.id}.jpg`);
- addToHistory(id);
- })
-
- $('.vid-row').first().click();
-
- $('.vid-table').each(function(){
- let id = $(this).attr('id');
- let table = new DataTable('#' + id, {
- responsive: true,
- columnDefs: [{ "width": "80%", "targets": 0 }]
- });
-
- document.getElementById(id).style.removeProperty('width');
- });
-
-
- $('.collapse').removeClass('show');
- //$('#dataTable-0-collapse-toggle').trigger('click');
-
- $('.folder-toggle').off('click.main').on('click.main', function(){
- var targetID = $(this).data('bs-target');
-
- if($(targetID).data('state') == 1){
- $(targetID).data('state', 0);
- $(this).empty().append('<i class="bi bi-list"></i> Show Folder');
- }
- else {
- $(targetID).data('state', 1);
- $(this).empty().append('<i class="bi bi-list"></i> Hide Folder');
- }
- });
-}
-
-function toggleDarkMode(){
- let rootHTML = document.querySelector('html');
- try {
- let darkModeToggle = document.getElementById('dark-mode-toggle');
- let currElemClass = !darkModeToggle.checked ? 'light-mode' : 'dark-mode';
- let nextElemClass = !darkModeToggle.checked ? 'dark-mode' : 'light-mode';
- let currBtnClass = !darkModeToggle.checked ? 'btn-light' : 'btn-dark';
- let nextBtnClass = !darkModeToggle.checked ? 'btn-dark' : 'btn-light';
-
- darkModeToggle.checked ? rootHTML.classList.remove("dark", "tw-dark") : rootHTML.classList.add("dark", "tw-dark");
-
- let elems = document.querySelectorAll('.' + currElemClass);
- let btns = document.querySelectorAll('.' + currBtnClass);
-
- for (let el of elems) {
- el.classList.replace(currElemClass, nextElemClass);
- }
-
- for (let btn of btns) {
- btn.classList.replace(currBtnClass, nextBtnClass);
- }
- } catch (error) {
- let darkModeToggle = {checked: true}
- let currElemClass = !darkModeToggle.checked ? 'light-mode' : 'dark-mode';
- let nextElemClass = !darkModeToggle.checked ? 'dark-mode' : 'light-mode';
- let currBtnClass = !darkModeToggle.checked ? 'btn-light' : 'btn-dark';
- let nextBtnClass = !darkModeToggle.checked ? 'btn-dark' : 'btn-light';
-
- darkModeToggle.checked ? rootHTML.classList.remove("dark", "tw-dark") : rootHTML.classList.add("dark", "tw-dark");
-
- let elems = document.querySelectorAll('.' + currElemClass);
- let btns = document.querySelectorAll('.' + currBtnClass);
-
- for (let el of elems) {
- el.classList.replace(currElemClass, nextElemClass);
- }
-
- for (let btn of btns) {
- btn.classList.replace(currBtnClass, nextBtnClass);
- }
- }
-}
-
-function getDarkModeSettings(){
- try {
- let darkModeToggle = document.getElementById('dark-mode-toggle');
- let currElemClass = darkModeToggle.checked ? 'light-mode' : 'dark-mode';
- let currBtnClass = darkModeToggle.checked ? 'btn-light' : 'btn-dark';
-
- return {
- elementClass: currElemClass,
- btnClass: currBtnClass
- }
- } catch (error) {
-
- let darkModeToggle = true;
- let currElemClass = darkModeToggle ? 'light-mode' : 'dark-mode';
- let currBtnClass = darkModeToggle ? 'btn-light' : 'btn-dark';
-
- return {
- elementClass: currElemClass,
- btnClass: currBtnClass
- }
- }
-}
\ No newline at end of file
diff --git a/resources/js/App.vue b/resources/js/App.vue
index b12b2fd2..c905c597 100644
--- a/resources/js/App.vue
+++ b/resources/js/App.vue
@@ -1,10 +1,11 @@
<script setup>
+ import ToastController from './components/pinesUI/ToastController.vue';
+
import { onMounted, watch } from 'vue';
import {RouterView} from 'vue-router'
import { storeToRefs } from 'pinia';
import { useAppStore } from './stores/AppStore';
- import PrimeToast from './components/primevue/PrimeToast.vue';
const appStore = useAppStore();
const { lightMode } = storeToRefs( appStore );
@@ -18,6 +19,6 @@
</script>
<template>
- <PrimeToast/>
+ <ToastController/>
<RouterView/>
</template>
\ No newline at end of file
diff --git a/resources/js/components/forms/EditVideo.vue b/resources/js/components/forms/EditVideo.vue
index 2ebc299b..3973854d 100644
--- a/resources/js/components/forms/EditVideo.vue
+++ b/resources/js/components/forms/EditVideo.vue
@@ -1,17 +1,17 @@
<script setup>
import useForm from '../../composables/useForm';
-import useToast from '../../composables/useToast';
import mediaAPI from '../../service/mediaAPI';
import FormInput from '../inputs/FormInput.vue';
import FormTextArea from '../inputs/FormTextArea.vue';
import FormInputLabel from '../labels/FormInputLabel.vue';
import { reactive } from 'vue';
+import { useToast } from '../../composables/useToast';
-const emit = defineEmits(['handleFinish','toast-show']);
+const emit = defineEmits(['handleFinish']);
const props = defineProps(['video']);
-const toast = useToast({emit});
+const toast = useToast();
const fields = reactive([
{
@@ -64,10 +64,10 @@ const handleSubmit = async () => {
{
onSuccess: (response) => {
emit('handleFinish', response?.data);
- toast.popToast('Edit submitted!');
+ toast.add({ type: 'success', title:'Success', description:'Edit submitted!', life: 3000});
},
onError: () => {
- toast.popToast('Unable to update video details.');
+ toast.add({ type: 'danger', title:'Error', description:'Unable to update video details.', life: 3000});
},
}
)
diff --git a/resources/js/components/pinesUI/ToastController.vue b/resources/js/components/pinesUI/ToastController.vue
new file mode 100644
index 00000000..937d24e0
--- /dev/null
+++ b/resources/js/components/pinesUI/ToastController.vue
@@ -0,0 +1,269 @@
+<script>
+import ToastEventBus from '../../service/toastEventBus';
+import ToastNotification from '../pinesUI/ToastNotification.vue';
+
+
+var messageIdx = 0;
+
+function UniqueComponentId(prefix = 'pv_id_') {
+ return prefix + Math.random().toString(16).slice(2);
+}
+
+export default {
+ name: 'ToastController',
+ emits: ['close'],
+ data() {
+ return {
+ messages: [],
+ positionRoot: 'bottom-left',
+ toastsHovered: false,
+ expanded: false,
+ layout: 'default',
+ paddingBetweenToasts: 16,
+ heightRecalculateTimeout: null
+ };
+ },
+ mounted() {
+ ToastEventBus.on('add', this.onAdd);
+ ToastEventBus.on('remove', this.onRemove);
+ ToastEventBus.on('remove-group', this.onRemoveGroup);
+ ToastEventBus.on('remove-all-groups', this.onRemoveAllGroups);
+ this.stackToasts();
+ },
+ beforeUnmount() {
+ ToastEventBus.off('add', this.onAdd);
+ ToastEventBus.off('remove', this.onRemove);
+ ToastEventBus.off('remove-group', this.onRemoveGroup);
+ ToastEventBus.off('remove-all-groups', this.onRemoveAllGroups);
+ },
+ watch: {
+ // whenever question changes, this function will run
+ toastsHovered(value) {
+ if (this.layout == 'default') {
+ // if (this.position.includes('bottom')) {
+ // this.resetBottom();
+ // } else {
+ // this.resetTop();
+ // }
+
+ if (value) {
+ // calculate the new positions
+ this.expanded = true;
+ if (this.layout == 'default') {
+ this.stackToasts();
+ }
+ } else {
+ if (this.layout == 'default') {
+ this.expanded = false;
+ // setTimeout(function(){
+ this.stackToasts();
+ // }, 10);
+ // setTimeout(function () {
+ // this.stackToasts();
+ // }, 10)
+ }
+ }
+ }
+ }
+ },
+ methods: {
+ add(message) {
+
+ if (message.position && this.positionIsValid(message.position)) this.positionRoot = message.position
+ if (message.type && !this.typeIsValid(message.type)) message.type = 'default';
+
+ if (message.idx == null) {
+ message.idx = messageIdx;
+ messageIdx++;
+ }
+
+ if (message.id == null) {
+ message.id = UniqueComponentId('toast_');
+ }
+
+ this.messages.unshift(message);
+ },
+ remove(params) {
+ // console.log(params.message.idx);
+
+ if (!params.message.idx) return;
+ // for (let i = 0; i < this.messages.length; i++) {
+ // if (this.messages[i].idx === params.message.idx) {
+ // console.log('found ' + params.message.idx);
+
+ // this.messages.splice(i, 1);
+ // break;
+ // }
+ // }
+ // if (this.messages[params.message.idx]) {
+ // // delete this.messages[params.message.idx]
+ // // this.$emit(params.type, { message: params.message });
+ // }
+ },
+ onAdd(message) {
+ if (this.group == message.group) {
+ this.add(message);
+ }
+ },
+ onRemove(message) {
+ this.remove({ message, type: 'close' });
+ },
+ onRemoveGroup(group) {
+ if (this.group === group) {
+ this.messages = [];
+ }
+ },
+ onRemoveAllGroups() {
+ this.messages = [];
+ },
+ stackToasts() {
+ this.positionToasts();
+ this.calculateHeightOfToastsContainer();
+ if (this.heightRecalculateTimeout) clearTimeout(this.heightRecalculateTimeout);
+
+ let that = this;
+ this.heightRecalculateTimeout = setTimeout(function () {
+ that.calculateHeightOfToastsContainer();
+ }, 300);
+ },
+ positionToasts() {
+ try {
+ let scaleBuffer = 1;
+ let yBuffer = -16;
+ let zBuffer = 100;
+ let bottomFlag = this.positionRoot.includes("bottom")
+ let totalHeight = 0;
+ let topToast = null;
+ for (let i = 0; i < this.messages.length; i++) {
+ const toast = document.getElementById(this.messages[i].id);
+ toast.style.zIndex = zBuffer;
+ if (zBuffer > 0) zBuffer -= 10;
+
+ yBuffer += 16;
+
+ if (this.expanded) {
+ totalHeight = totalHeight + (totalHeight ? this.paddingBetweenToasts : 0);
+
+ if (bottomFlag) {
+ toast.style.top = "auto";
+ toast.style.bottom = totalHeight + "px";
+ }
+ else toast.style.top = totalHeight + "px";
+
+ totalHeight += toast.getBoundingClientRect().height;
+ toast.style.scale = 1;
+ continue;
+ }
+
+ toast.style.top = "auto";
+ toast.style.bottom = "auto";
+ toast.style.scale = scaleBuffer;
+ toast.style.transform = yBuffer ? `translateY(${bottomFlag ? '-' : ''}${yBuffer}px)` : '';
+ if (i === 0) topToast = toast;
+ else this.alignBottom(topToast, toast);
+ scaleBuffer -= 0.06;
+ }
+
+ if(this.messages[3]) {
+ let burnToast = document.getElementById(this.messages[3].id) ;
+ burnToast.classList.remove("opacity-100");
+ burnToast.classList.add("opacity-0");
+ this.messages.splice(3, 1);
+ this.stackToasts();
+ // let that = this;
+ // // Burn 🔥 (remove) last toast
+ // setTimeout(function () {
+ // for (let i = 0; i < that.messages.length; i++) {
+ // if (that.messages[i].idx === burnToast.idx) {
+ // that.messages.splice(i, 1);
+ // break;
+ // }
+ // }
+ // }, 300);
+
+ // if (bottomFlag && this.messages[1]) {
+ // this.messages[1].style.top = "auto";
+ // }
+ }
+ } catch (error) {
+ console.log(error);
+ }
+ },
+ alignBottom(element1, element2) {
+ // Get the top position and height of the first element
+ let top1 = element1.offsetTop;
+ let height1 = element1.offsetHeight;
+
+ // Get the height of the second element
+ let height2 = element2.offsetHeight;
+
+ // Calculate the top position for the second element
+ let top2 = top1 + (height1 - height2);
+
+ // Apply the calculated top position to the second element
+ element2.style.top = top2 + "px";
+ },
+ calculateHeightOfToastsContainer() {
+ if (this.messages.length == 0) {
+ this.$refs.container.style.height = "0px";
+ return;
+ }
+
+ let lastToast = this.messages[this.messages.length - 1];
+ let lastToastRectangle = document.getElementById(lastToast.id).getBoundingClientRect();
+
+ let firstToast = this.messages[0];
+ let firstToastRectangle = document.getElementById(firstToast.id).getBoundingClientRect();
+
+ if (this.toastsHovered) {
+ if (this.positionRoot.includes("bottom")) {
+ this.$refs.container.style.height =
+ firstToastRectangle.top +
+ firstToastRectangle.height -
+ lastToastRectangle.top +
+ "px";
+ } else {
+ this.$refs.container.style.height =
+ lastToastRectangle.top +
+ lastToastRectangle.height -
+ firstToastRectangle.top +
+ "px";
+ }
+ } else {
+ this.$refs.container.style.height = firstToastRectangle.height + "px";
+ }
+ },
+ positionIsValid(newPosition) {
+ return newPosition == 'top-right' || newPosition == 'top-left' || newPosition == 'top-center' || newPosition == 'bottom-right' || newPosition == 'bottom-left' || newPosition == 'bottom-center'
+ },
+ typeIsValid(newType) {
+ return newType == 'success' || newType == 'info' || newType == 'warning' || newType == 'danger' || newType == 'default'
+ }
+ },
+ components: {
+ ToastNotification: ToastNotification
+ }
+
+};
+</script>
+
+<template>
+ <teleport to='body'>
+ <ul class="fixed w-full group z-[99] sm:max-w-xs" id="toastRoot"
+ :class="{ 'right-0 top-0 sm:mt-6 sm:mr-6': positionRoot == 'top-right', 'left-0 top-0 sm:mt-6 sm:ml-6': positionRoot == 'top-left', 'left-1/2 -translate-x-1/2 top-0 sm:mt-6': positionRoot == 'top-center', 'right-0 bottom-0 sm:mr-6 sm:mb-6': positionRoot == 'bottom-right', 'left-0 bottom-0 sm:ml-6 sm:mb-6': positionRoot == 'bottom-left', 'left-1/2 -translate-x-1/2 bottom-0 sm:mb-6': positionRoot == 'bottom-center' }"
+ v-cloak ref="container"
+ @mouseenter="toastsHovered=true;"
+ @mouseleave="toastsHovered=false">
+ <ToastNotification v-for="toast in messages" :key="toast.idx" :type="toast.type" v-bind="toast" :stack="stackToasts"
+ :count="messages.length" @close="(event) => {
+ for (let i = 0; i < messages.length; i++) {
+ if (messages[i].idx === toast.idx) {
+ messages.splice(i, 1);
+ stackToasts();
+ break;
+ }
+ }
+ }" />
+ </ul>
+ </teleport>
+</template>
\ No newline at end of file
diff --git a/resources/js/components/pinesUI/ToastNotification.vue b/resources/js/components/pinesUI/ToastNotification.vue
index 4615412c..5935c196 100644
--- a/resources/js/components/pinesUI/ToastNotification.vue
+++ b/resources/js/components/pinesUI/ToastNotification.vue
@@ -1,8 +1,12 @@
<script setup>
-import { onBeforeUnmount, onMounted, ref, watch } from 'vue';
+import { onBeforeUnmount, onMounted, ref } from 'vue';
const emit = defineEmits(['close'])
const props = defineProps({
+ type: {
+ type: String,
+ default: 'default'
+ },
position: {
type: String,
default: 'bottom-right'
@@ -21,78 +25,42 @@ const props = defineProps({
type: String,
default: 'Title'
},
- message: {
- type: String,
- default: 'Hi'
- },
description: {
type: String,
- default: 'Description'
},
count: {
type: Number,
required: true
},
- deleted: {
- type: Boolean,
- value: false
+ html: {
+ default: ''
+ },
+ isValid: {
+ type: Boolean
+ },
+ stack: {
+ type: Function,
+ default: () => {}
}
});
const toastHovered = ref(false);
const mounted = ref(false);
-
const animateTimeout = ref(null);
const closeTimeout = ref(null);
-
+const stackTimeout = ref(null);
onMounted(() => {
- // let el = document.querySelector(`#${props.id}`)
- // if (props.position.includes('bottom')) {
- // el.classList.add('toast-bottom');
- // el.classList.add('opacity-0', 'translate-y-full');
- // } else {
- // el.classList.add('opacity-0', 'translate-y-full');
- // }
-
- // setTimeout(function () {
- // setTimeout(function () {
- // if (props.position.includes('bottom')) {
- // el.classList.remove('opacity-0', 'translate-y-full');
- // } else {
- // el.classList.remove('opacity-0', '-translate-y-full');
- // }
- // el.classList.add('opacity-100', 'translate-y-0');
-
- // // setTimeout(function () {
- // // toastRootData.stackToasts();
- // // }, 10);
- // }, 5);
- // }, 50);
-
- // setTimeout(function () {
- // setTimeout(function () {
- // el.classList.remove('opacity-100');
- // el.classList.add('opacity-0');
- // // if (toastRootData.toasts.length == 1) {
- // // el.classList.remove('translate-y-0');
- // // el.classList.add('-translate-y-full');
- // // }
- // closeTimeout.value = setTimeout(() => {
- // close({ message: { idx: props.idx }, type: 'life-end' });
- // }, props.life);
- // setTimeout(function () {
- // // toastRootData.deleteToastWithId(props.id)
+ mounted.value = true;
- // }, 300);
- // }, 5);
- // }, 4000);
+ if(stackTimeout.value) clearTimeout(stackTimeout);
- mounted.value = true;
+ stackTimeout.value = setTimeout(() => {
+ props.stack();
+ })
if (props.life) {
animateClose();
}
-
})
onBeforeUnmount(() => {
@@ -102,15 +70,18 @@ onBeforeUnmount(() => {
function close(params) {
emit('close', params);
};
+
function onCloseClick() {
mounted.value = false;
closeTimeout.value = setTimeout(() => {
- console.log('close animate ' + closeTimeout.value);
-
close({ message: { idx: props.idx }, type: 'life-end' });
- }, 300);
+ }, 500);
};
function clearCloseTimeout() {
+ if(stackTimeout.value){
+ clearTimeout(stackTimeout);
+ stackTimeout.value = null;
+ }
if (animateTimeout.value) {
clearTimeout(animateTimeout);
animateTimeout.value = null;
@@ -127,63 +98,59 @@ function animateClose() {
}, props.life)
}
-watch(() => closeTimeout.value, (value) => {console.log('close timeout changed for ' + props.idx + ' to ' + value)})
</script>
<template>
- <Transition
- enter-active-class="ease-out duration-300"
+ <Transition enter-active-class="ease-out duration-300"
:enter-from-class="`opacity-0 ${props.position.includes('bottom') ? 'translate-y-full' : '-translate-y-full'}`"
- :enter-to-class="`opacity-100 translate-y-0`"
- leave-active-class="ease-in duration-300"
- :leave-from-class="`opacity-100 translate-y-0`"
- :leave-to-class="`opacity-0 ${props.count == 1 ? (props.position.includes('bottom') ? 'translate-y-full' : '-translate-y-full') : ''}`"
- >
+ :enter-to-class="`opacity-100 translate-y-0`" leave-active-class="ease-out duration-300"
+ :leave-from-class="`opacity-100 translate-y-0`"
+ :leave-to-class="`opacity-0 ${props.count == 1 ? (props.position.includes('bottom') ? 'translate-y-full' : '-translate-y-full') : 'translate-y-0'}`">
<li v-show="mounted" :id="props.id" @mouseover="toastHovered = true" @mouseout="toastHovered = false"
- class="select-none sm:max-w-xs" :class="{ 'toast-no-description': !props.description }">
+ class="absolute w-full duration-300 ease-out select-none sm:max-w-xs" :class="{'toast-no-description' : !props.description}">
<span
- class="relative flex flex-col items-start shadow-[0_5px_15px_-3px_rgb(0_0_0_/_0.08)] w-full transition-all duration-300 ease-out bg-white border border-gray-100 sm:rounded-md sm:max-w-xs group p-4">
- <div class="relative">
+ class="relative flex flex-col items-start shadow-[0_5px_15px_-3px_rgb(0_0_0_/_0.08)] w-full transition-all duration-300 ease-out border bg-white dark:bg-neutral-800 border-gray-100 dark:border-neutral-700 text-gray-800 dark:text-neutral-100 sm:rounded-md sm:max-w-xs group"
+ :class="{ 'p-4': !props.html, 'p-0': props.html }">
+ <div v-if="!props.html" class="relative">
<div class="flex items-center"
- :class="{ 'text-green-500': props.type == 'success', 'text-blue-500': props.type == 'info', 'text-orange-400': props.type == 'warning', 'text-red-500': props.type == 'danger', 'text-gray-800': props.type == 'default' }">
+ :class="{ 'text-green-500': props.type == 'success', 'text-blue-500': props.type == 'info', 'text-orange-400': props.type == 'warning', 'text-red-500': props.type == 'danger', 'dark:text-neutral-100 text-gray-800': props.type == 'default' }">
- <svg v-show="props.type == 'success'" class="w-[18px] h-[18px] mr-1.5 -ml-1" viewBox="0 0 24 24"
- fill="none" xmlns="http://www.w3.org/2000/svg">
+ <svg v-show="props.type=='success'" class="w-[18px] h-[18px] mr-1.5 -ml-1"
+ viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd"
d="M12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22C17.5228 22 22 17.5228 22 12C22 6.47715 17.5228 2 12 2ZM16.7744 9.63269C17.1238 9.20501 17.0604 8.57503 16.6327 8.22559C16.2051 7.87615 15.5751 7.93957 15.2256 8.36725L10.6321 13.9892L8.65936 12.2524C8.24484 11.8874 7.61295 11.9276 7.248 12.3421C6.88304 12.7566 6.92322 13.3885 7.33774 13.7535L9.31046 15.4903C10.1612 16.2393 11.4637 16.1324 12.1808 15.2547L16.7744 9.63269Z"
fill="currentColor"></path>
</svg>
- <svg v-show="props.type == 'info'" class="w-[18px] h-[18px] mr-1.5 -ml-1" viewBox="0 0 24 24"
+ <svg v-show="props.type=='info'" class="w-[18px] h-[18px] mr-1.5 -ml-1" viewBox="0 0 24 24"
fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd"
d="M12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22C17.5228 22 22 17.5228 22 12C22 6.47715 17.5228 2 12 2ZM12 9C12.5523 9 13 8.55228 13 8C13 7.44772 12.5523 7 12 7C11.4477 7 11 7.44772 11 8C11 8.55228 11.4477 9 12 9ZM13 12C13 11.4477 12.5523 11 12 11C11.4477 11 11 11.4477 11 12V16C11 16.5523 11.4477 17 12 17C12.5523 17 13 16.5523 13 16V12Z"
fill="currentColor"></path>
</svg>
- <svg v-show="props.type == 'warning'" class="w-[18px] h-[18px] mr-1.5 -ml-1" viewBox="0 0 24 24"
- fill="none" xmlns="http://www.w3.org/2000/svg">
+ <svg v-show="props.type=='warning'" class="w-[18px] h-[18px] mr-1.5 -ml-1"
+ viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd"
d="M9.44829 4.46472C10.5836 2.51208 13.4105 2.51168 14.5464 4.46401L21.5988 16.5855C22.7423 18.5509 21.3145 21 19.05 21L4.94967 21C2.68547 21 1.25762 18.5516 2.4004 16.5862L9.44829 4.46472ZM11.9995 8C12.5518 8 12.9995 8.44772 12.9995 9V13C12.9995 13.5523 12.5518 14 11.9995 14C11.4473 14 10.9995 13.5523 10.9995 13V9C10.9995 8.44772 11.4473 8 11.9995 8ZM12.0009 15.99C11.4486 15.9892 11.0003 16.4363 10.9995 16.9886L10.9995 16.9986C10.9987 17.5509 11.4458 17.9992 11.9981 18C12.5504 18.0008 12.9987 17.5537 12.9995 17.0014L12.9995 16.9914C13.0003 16.4391 12.5532 15.9908 12.0009 15.99Z"
fill="currentColor"></path>
</svg>
- <svg v-show="props.type == 'danger'" class="w-[18px] h-[18px] mr-1.5 -ml-1" viewBox="0 0 24 24"
- fill="none" xmlns="http://www.w3.org/2000/svg">
+ <svg v-show="props.type=='danger'" class="w-[18px] h-[18px] mr-1.5 -ml-1"
+ viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd"
d="M2 12C2 6.47715 6.47715 2 12 2C17.5228 2 22 6.47715 22 12C22 17.5228 17.5228 22 12 22C6.47715 22 2 17.5228 2 12ZM11.9996 7C12.5519 7 12.9996 7.44772 12.9996 8V12C12.9996 12.5523 12.5519 13 11.9996 13C11.4474 13 10.9996 12.5523 10.9996 12V8C10.9996 7.44772 11.4474 7 11.9996 7ZM12.001 14.99C11.4488 14.9892 11.0004 15.4363 10.9997 15.9886L10.9996 15.9986C10.9989 16.5509 11.446 16.9992 11.9982 17C12.5505 17.0008 12.9989 16.5537 12.9996 16.0014L12.9996 15.9914C13.0004 15.4391 12.5533 14.9908 12.001 14.99Z"
fill="currentColor"></path>
</svg>
- <p class="text-[13px] font-medium leading-none text-gray-800">{{ props.message }}</p>
+ <p class="text-[13px] font-medium leading-none">{{ props.title }}</p>
</div>
- <p v-show="props.description" :class="{ 'pl-5': props.type != 'default' }"
+ <p v-show="props.description" :class="{ 'pl-5': props.type !== 'default' }"
class="mt-1.5 text-xs leading-none opacity-70">{{ props.description }}</p>
</div>
<span @click="onCloseClick"
- class="absolute right-0 p-1.5 mr-2.5 text-gray-400 duration-100 ease-in-out rounded-full opacity-0 cursor-pointer hover:bg-gray-50 hover:text-gray-500"
- :class="{ 'top-1/2 -translate-y-1/2': !props.description, 'top-0 mt-2.5': (props.description), 'opacity-100': toastHovered, 'opacity-0': !toastHovered }">
+ class="absolute right-0 p-1.5 mr-2.5 text-gray-400 dark:text-rose-700 duration-100 ease-in-out rounded-full opacity-0 cursor-pointer hover:bg-gray-50 dark:bg-gray-800/50 hover:text-gray-500 dark:hover:text-rose-600"
+ :class="{ 'top-1/2 -translate-y-1/2': !props.description && !props.html, 'top-0 mt-2.5': (props.description || props.html), 'opacity-100': toastHovered, 'opacity-0': !toastHovered }">
<svg class="w-3 h-3" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd"
d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z"
- clip-rule="evenodd">
- </path>
+ clip-rule="evenodd"></path>
</svg>
</span>
</span>
diff --git a/resources/js/components/pinesUI/ToastRoot.vue b/resources/js/components/pinesUI/ToastRoot.vue
deleted file mode 100644
index 16768ffd..00000000
--- a/resources/js/components/pinesUI/ToastRoot.vue
+++ /dev/null
@@ -1,71 +0,0 @@
-<script setup>
-import { onMounted, ref } from 'vue';
-import useToastController from '../../composables/useToastController';
-import ToastNotification from './ToastNotification.vue';
-
-const $el = ref(null);
-const { layout, position } = defineProps(['layout', 'position'])
-
-const toastController = useToastController($el, layout, position);
-
-window.toast = function (message, options = {}) {
- let description = "";
- let type = "default";
- let position = "bottom-left";
- let html = "";
- if (typeof options.description != "undefined")
- description = options.description;
- if (typeof options.type != "undefined") type = options.type;
- if (typeof options.position != "undefined") position = options.position;
- if (typeof options.html != "undefined") html = options?.html;
- return new CustomEvent('toast-show', { detail : { type: type, message: message, description: description, position : position, html: html }})
-};
-
-onMounted(() => {
- if (toastController.layout == 'expanded') {
- toastController.expanded = true;
- }
- toastController.stackToasts();
-})
-
-const handleSetLayout = (event) => {
- toastController.layout = event.detail.layout;
- if (layout == 'expanded') {
- toastController.expanded = true;
- } else {
- toastController.expanded = false;
- }
- toastController.stackToasts();
-}
-
-const handleToastShow = (event) => {
- event.stopPropagation();
- if (event.detail.position) {
- toastController.position = event.detail.position;
- }
- toastController.toasts.unshift({
- id: 'toast-' + Math.random().toString(16).slice(2),
- show: false,
- message: event.detail.message,
- title: event.detail.title,
- description: event.detail.description,
- type: event.detail.type,
- html: event.detail.html
- });
-}
-
-</script>
-<template>
- <Teleport to="body">
- <ul class="fixed block w-full group z-[99] sm:max-w-xs" id="toastRoot"
- :class="{ 'right-0 top-0 sm:mt-6 sm:mr-6': position == 'top-right', 'left-0 top-0 sm:mt-6 sm:ml-6': position == 'top-left', 'left-1/2 -translate-x-1/2 top-0 sm:mt-6': position == 'top-center', 'right-0 bottom-0 sm:mr-6 sm:mb-6': position == 'bottom-right', 'left-0 bottom-0 sm:ml-6 sm:mb-6': position == 'bottom-left', 'left-1/2 -translate-x-1/2 bottom-0 sm:mb-6': position == 'bottom-center' }"
- v-cloak @mouseenter="toastController.toastsHovered = true;"
- @mouseleave="toastController.toastsHovered = false" ref="$el">
- <template v-for="(toast, index) in toastController.toasts" :key="index">
- <ToastNotification :position="position" :toast="toast" :toastRootData="toastController" :root="$el" />
- </template>
- </ul>
- </Teleport>
- <slot name="app" :handleSetLayout="handleSetLayout" :handleToastShow="handleToastShow">
- </slot>
-</template>
\ No newline at end of file
diff --git a/resources/js/components/primevue/PrimeBaseToast.vue b/resources/js/components/primevue/PrimeBaseToast.vue
deleted file mode 100644
index e8def41a..00000000
--- a/resources/js/components/primevue/PrimeBaseToast.vue
+++ /dev/null
@@ -1,58 +0,0 @@
-<script>
-
-export default {
- name: 'BaseToast',
- props: {
- group: {
- type: String,
- default: null
- },
- position: {
- type: String,
- default: 'top-right'
- },
- autoZIndex: {
- type: Boolean,
- default: true
- },
- baseZIndex: {
- type: Number,
- default: 0
- },
- breakpoints: {
- type: Object,
- default: null
- },
- closeIcon: {
- type: String,
- default: undefined
- },
- infoIcon: {
- type: String,
- default: undefined
- },
- warnIcon: {
- type: String,
- default: undefined
- },
- errorIcon: {
- type: String,
- default: undefined
- },
- successIcon: {
- type: String,
- default: undefined
- },
- closeButtonProps: {
- type: null,
- default: null
- }
- },
- provide() {
- return {
- $pcToast: this,
- $parentInstance: this
- };
- }
-};
-</script>
\ No newline at end of file
diff --git a/resources/js/components/primevue/PrimeToast.vue b/resources/js/components/primevue/PrimeToast.vue
deleted file mode 100644
index 66147ed5..00000000
--- a/resources/js/components/primevue/PrimeToast.vue
+++ /dev/null
@@ -1,105 +0,0 @@
-<script>
-import ToastEventBus from '../../service/toastEventBus';
-import PrimeBaseToast from './PrimeBaseToast.vue';
-import ToastNotification from '../pinesUI/ToastNotification.vue';
-
-
-var messageIdx = 0;
-
-function isEmpty(value) {
- return value === null || value === undefined || value === '' || (Array.isArray(value) && value.length === 0) || (!(value instanceof Date) && typeof value === 'object' && Object.keys(value).length === 0);
-}
-
-
-function UniqueComponentId(prefix = 'pv_id_') {
- return prefix + Math.random().toString(16).slice(2);
-}
-
-export default {
- name: 'PrimeToast',
- extends: PrimeBaseToast,
- emits: ['close'],
- data() {
- return {
- messages: {},
- positionRoot: 'bottom-left'
- };
- },
- mounted() {
- ToastEventBus.on('add', this.onAdd);
- ToastEventBus.on('remove', this.onRemove);
- ToastEventBus.on('remove-group', this.onRemoveGroup);
- ToastEventBus.on('remove-all-groups', this.onRemoveAllGroups);
- },
- beforeUnmount() {
- ToastEventBus.off('add', this.onAdd);
- ToastEventBus.off('remove', this.onRemove);
- ToastEventBus.off('remove-group', this.onRemoveGroup);
- ToastEventBus.off('remove-all-groups', this.onRemoveAllGroups);
- },
- methods: {
- add(message) {
-
- if(message.position && this.positionIsValid(message.position)) this.positionRoot = message.position
- if (message.idx == null) {
- message.idx = messageIdx++;
- }
-
- if(message.id == null) {
- message.id = UniqueComponentId('toast_');
- }
-
- let stack = {...this.messages};
- stack[message.idx] = message;
- this.messages = {...stack};
- },
- async remove(params) {
- if (this.messages[params.message.idx]) {
- this.messages[params.message.idx] = {};
- // this.$emit(params.type, { message: params.message });
- }
- },
- onAdd(message) {
- if (this.group == message.group) {
- this.add(message);
- }
- },
- onRemove(message) {
- console.log(`remove ${message.idx}`);
-
- this.remove({ message, type: 'close' });
- },
- onRemoveGroup(group) {
- if (this.group === group) {
- this.messages = {};
- }
- },
- onRemoveAllGroups() {
- this.messages = {};
- },
- positionIsValid(newPosition) {
- return newPosition == 'top-right' || newPosition == 'top-left' || newPosition == 'top-center' || newPosition == 'bottom-right' || newPosition == 'bottom-left' || newPosition == 'bottom-center'
- }
- },
- computed: {
- attributeSelector() {
- return UniqueComponentId();
- }
- },
- components: {
- ToastNotification: ToastNotification
- }
-};
-</script>
-
-<template>
- <teleport to='body'>
- <ul class="fixed w-full group z-[99] sm:max-w-xs flex flex-col gap-4" id="toastRoot"
- :class="{ 'right-0 top-0 sm:mt-6 sm:mr-6': positionRoot == 'top-right', 'left-0 top-0 sm:mt-6 sm:ml-6': positionRoot == 'top-left', 'left-1/2 -translate-x-1/2 top-0 sm:mt-6': positionRoot == 'top-center', 'right-0 bottom-0 sm:mr-6 sm:mb-6': positionRoot == 'bottom-right', 'left-0 bottom-0 sm:ml-6 sm:mb-6': positionRoot == 'bottom-left', 'left-1/2 -translate-x-1/2 bottom-0 sm:mb-6': positionRoot == 'bottom-center' }"
- v-cloak ref="container">
- <ToastNotification v-for="(toast, index) in Object.values(messages)" :key="index" v-bind="toast" :count="Object.keys(messages).length" @close="async (event) => {
- remove(event);
- }"/>
- </ul>
- </teleport>
-</template>
\ No newline at end of file
diff --git a/resources/js/components/primevue/PrimeToastMessage.vue b/resources/js/components/primevue/PrimeToastMessage.vue
deleted file mode 100644
index ec12a88c..00000000
--- a/resources/js/components/primevue/PrimeToastMessage.vue
+++ /dev/null
@@ -1,156 +0,0 @@
-<template>
- <!-- <div :class="[cx('message'), message.styleClass]" role="alert" aria-live="assertive" aria-atomic="true"
- v-bind="ptm('message')">
- <component v-if="templates.container" :is="templates.container" :message="message"
- :closeCallback="onCloseClick" />
- <div v-else :class="[cx('messageContent'), message.contentStyleClass]" v-bind="ptm('messageContent')">
- <template v-if="!templates.message">
- <component
- :is="templates.messageicon ? templates.messageicon : templates.icon ? templates.icon : iconComponent && iconComponent.name ? iconComponent : 'span'"
- :class="cx('messageIcon')" v-bind="ptm('messageIcon')" />
- <div :class="cx('messageText')" v-bind="ptm('messageText')">
- <span :class="cx('summary')" v-bind="ptm('summary')">{{ message.summary }}</span>
- <div :class="cx('detail')" v-bind="ptm('detail')">{{ message.detail }}</div>
- </div>
- </template>
- <component v-else :is="templates.message" :message="message"></component>
- <div v-if="message.closable !== false" v-bind="ptm('buttonContainer')">
- <button v-ripple :class="cx('closeButton')" type="button" :aria-label="closeAriaLabel"
- @click="onCloseClick" autofocus v-bind="{ ...closeButtonProps, ...ptm('closeButton') }">
- <component :is="templates.closeicon || 'TimesIcon'" :class="[cx('closeIcon'), closeIcon]"
- v-bind="ptm('closeIcon')" />
- </button>
- </div>
- </div>
- </div> -->
- <div
- class="absolute bottom-0 flex flex-col items-start shadow-[0_5px_15px_-3px_rgb(0_0_0_/_0.08)] w-full bg-white border border-gray-100 sm:rounded-md sm:max-w-xs group p-4">
- <div class="relative">
- <div class="flex items-center text-green-500">
-
- <svg class="w-[18px] h-[18px] mr-1.5 -ml-1" viewBox="0 0 24 24" fill="none"
- xmlns="http://www.w3.org/2000/svg">
- <path fill-rule="evenodd" clip-rule="evenodd"
- d="M12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22C17.5228 22 22 17.5228 22 12C22 6.47715 17.5228 2 12 2ZM16.7744 9.63269C17.1238 9.20501 17.0604 8.57503 16.6327 8.22559C16.2051 7.87615 15.5751 7.93957 15.2256 8.36725L10.6321 13.9892L8.65936 12.2524C8.24484 11.8874 7.61295 11.9276 7.248 12.3421C6.88304 12.7566 6.92322 13.3885 7.33774 13.7535L9.31046 15.4903C10.1612 16.2393 11.4637 16.1324 12.1808 15.2547L16.7744 9.63269Z"
- fill="currentColor"></path>
- </svg>
- <p class="text-[13px] font-medium leading-none text-gray-800">{{ 'NAAAA' }}</p>
- </div>
- <p :class="{ 'pl-5': true }" class="mt-1.5 text-xs leading-none opacity-70">{{ 'De' }}</p>
- </div>
- <span
- class="absolute right-0 p-1.5 mr-2.5 text-gray-400 duration-100 ease-in-out rounded-full opacity-0 cursor-pointer hover:bg-gray-50 hover:text-gray-500">
- <!--:class="{ 'top-1/2 -translate-y-1/2': !props.toast.description, 'top-0 mt-2.5': (props.toast.description), 'opacity-100': toastHovered, 'opacity-0': !toastHovered }"-->
- <svg class="w-3 h-3" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" @click="onCloseClick">
- <path fill-rule="evenodd"
- d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z"
- clip-rule="evenodd">
- </path>
- </svg>
- </span>
- </div>
-</template>
-
-<script>
-// import BaseComponent from '@primevue/core/basecomponent';
-// import CheckIcon from '@primevue/icons/check';
-// import ExclamationTriangleIcon from '@primevue/icons/exclamationtriangle';
-// import InfoCircleIcon from '@primevue/icons/infocircle';
-// import TimesIcon from '@primevue/icons/times';
-// import TimesCircleIcon from '@primevue/icons/timescircle';
-// import Ripple from 'primevue/ripple';
-
-export default {
- type: 'default',
- name: 'ToastMessage',
- description: 'des',
- hostName: 'Toast',
- // extends: BaseComponent,
- emits: ['close'],
- closeTimeout: null,
- props: {
- message: {
- type: null,
- default: null
- },
- templates: {
- type: Object,
- default: null
- },
- closeIcon: {
- type: String,
- default: null
- },
- infoIcon: {
- type: String,
- default: null
- },
- warnIcon: {
- type: String,
- default: null
- },
- errorIcon: {
- type: String,
- default: null
- },
- successIcon: {
- type: String,
- default: null
- },
- closeButtonProps: {
- type: null,
- default: null
- }
- },
- mounted() {
- if (this.message.life) {
- this.closeTimeout = setTimeout(() => {
- this.close({ message: this.message, type: 'life-end' });
- }, this.message.life);
- }
- },
- beforeUnmount() {
- this.clearCloseTimeout();
- },
- methods: {
- close(params) {
- console.log('prine close dont work');
-
- this.$emit('close', params);
- },
- onCloseClick() {
- this.clearCloseTimeout();
- this.close({ message: this.message, type: 'close' });
- },
- clearCloseTimeout() {
- if (this.closeTimeout) {
- clearTimeout(this.closeTimeout);
- this.closeTimeout = null;
- }
- }
- },
- computed: {
- // iconComponent() {
- // return {
- // info: !this.infoIcon && InfoCircleIcon,
- // success: !this.successIcon && CheckIcon,
- // warn: !this.warnIcon && ExclamationTriangleIcon,
- // error: !this.errorIcon && TimesCircleIcon
- // }[this.message.severity];
- // },
- // closeAriaLabel() {
- // return this.$primevue.config.locale.aria ? this.$primevue.config.locale.aria.close : undefined;
- // }
- },
- // components: {
- // TimesIcon: TimesIcon,
- // InfoCircleIcon: InfoCircleIcon,
- // CheckIcon: CheckIcon,
- // ExclamationTriangleIcon: ExclamationTriangleIcon,
- // TimesCircleIcon: TimesCircleIcon
- // },
- // directives: {
- // ripple: Ripple
- // }
-};
-</script>
\ No newline at end of file
diff --git a/resources/js/composables/usePrimeToast.js b/resources/js/composables/usePrimeToast.js
deleted file mode 100644
index 8d69589d..00000000
--- a/resources/js/composables/usePrimeToast.js
+++ /dev/null
@@ -1,13 +0,0 @@
-import { inject } from 'vue';
-
-export const ToastSymbol = Symbol();
-
-export function usePrimeToast() {
- const Toast = inject(ToastSymbol);
-
- if (!Toast) {
- throw new Error('No Toast provided!');
- }
-
- return Toast;
-}
\ No newline at end of file
diff --git a/resources/js/composables/useToast.js b/resources/js/composables/useToast.js
index ad8cd89d..d129d657 100644
--- a/resources/js/composables/useToast.js
+++ b/resources/js/composables/useToast.js
@@ -1,26 +1,13 @@
-import { reactive } from "vue";
+import { inject } from 'vue';
-export default function useToast(props) {
- const toast = reactive({
- title: props?.title ?? "Default Toast Notification",
- description: props?.description ?? "",
- type: props?.type ?? "default",
- position: "top-center",
- expanded: false,
- popToast(title, type, description) {
- if(title) this.title = title;
- if(type) this.type = type;
- if(description) this.description = description;
- if(props?.emit) {
- props.emit('toast-show', window.toast(this.title, {
- description: this.description,
- type: this.type,
- position: this.position,
- html: null,
- }));
- }
- },
- });
+export const ToastSymbol = Symbol();
- return toast;
-}
+export function useToast() {
+ const Toast = inject(ToastSymbol);
+
+ if (!Toast) {
+ throw new Error('No Toast provided!');
+ }
+
+ return Toast;
+}
\ No newline at end of file
diff --git a/resources/js/service/toastService.js b/resources/js/service/toastService.js
index 18942423..76567d26 100644
--- a/resources/js/service/toastService.js
+++ b/resources/js/service/toastService.js
@@ -1,4 +1,4 @@
-import { ToastSymbol } from '../composables/usePrimeToast';
+import { ToastSymbol } from '../composables/useToast';
import ToastEventBus from './toastEventBus';
export default {
diff --git a/resources/js/views/HistoryView.vue b/resources/js/views/HistoryView.vue
index 2317a224..c91cceed 100644
--- a/resources/js/views/HistoryView.vue
+++ b/resources/js/views/HistoryView.vue
@@ -4,15 +4,14 @@ import LayoutBase from '../components/layout/LayoutBase.vue';
import ModalBase from '../components/pinesUI/ModalBase.vue';
import useModal from '../composables/useModal';
import TableBase from '../components/table/TableBase.vue';
-import useToast from '../composables/useToast';
import { storeToRefs } from 'pinia';
import { useAppStore } from '../stores/AppStore';
import { useContentStore } from '../stores/ContentStore';
import { computed, onMounted, ref } from 'vue';
+import { useToast } from '../composables/useToast';
-const emit = defineEmits(['handleFinish','toast-show']);
-const toast = useToast({emit});
+const toast = useToast();
const appStore = useAppStore();
const ContentStore = useContentStore();
@@ -46,8 +45,8 @@ const handleDelete = (id) => {
const submitDelete = async () => {
if (cachedID.value) {
let request = await deleteRecord(cachedID.value);
- if(request) toast.popToast('Record Deleted Successfully!', 'success');
- else toast.popToast('Unable to delete record.', 'danger');
+ if(request) toast.add({ type: 'success', title:'Success', description:'Record Deleted Successfully!', life: 3000});
+ else toast.add({ type: 'warning', title:'Error', description:'Unable to delete record. Please try again.', life: 3000});
}
}
diff --git a/resources/js/views/ProfileView.vue b/resources/js/views/ProfileView.vue
index a86d2064..f964dd39 100644
--- a/resources/js/views/ProfileView.vue
+++ b/resources/js/views/ProfileView.vue
@@ -1,23 +1,16 @@
<script setup>
import LayoutBase from '../components/layout/LayoutBase.vue';
-import useToast from '../composables/useToast';
+import { useToast } from '../composables/useToast';
import ButtonText from '../components/inputs/ButtonText.vue'
import { onMounted } from 'vue';
import { useAppStore } from '../stores/AppStore';
import { storeToRefs } from 'pinia';
-const emit = defineEmits(['toast-show']);
-const toast = useToast({emit});
-
+const toast = useToast();
const appStore = useAppStore();
-
const { pageTitle, selectedSideBar } = storeToRefs(appStore);
-
-import { usePrimeToast } from '../composables/usePrimeToast';
-
-const primeToast = usePrimeToast();
onMounted(() => {
pageTitle.value = "Tests";
selectedSideBar.value = '';
@@ -33,15 +26,26 @@ onMounted(() => {
<div class="relative">
<p class="mb-2 text-xs font-medium text-center text-gray-500 sm:text-left">Tests</p>
<div class="relative flex flex-col px-10 space-y-2 sm:space-x-5 sm:space-y-0 sm:flex-row sm:px-0">
- <ButtonText @click="toast.popToast();">
+ <ButtonText @click="toast.add({ type: 'danger', title:'Default Toast Notification', description:'This is an example toast notification', life: 3000});">
<template #text>
Test Notification
</template>
</ButtonText>
- <button class="inline-flex items-center justify-center flex-shrink-0 px-3 py-1 text-xs font-medium transition-colors border rounded-md h-9 hover:bg-gray-50 active:bg-white focus:bg-white focus:outline-none"
- @click="primeToast.add({ severity: 'info', summary: 'Info', detail: 'Message Content', life: 3000, position: 'top-right' })">
- Prime
- </button>
+ <ButtonText @click="toast.add({ type: 'success', title:'Default Toast Notification', description:'This is an example toast notification', life: 3000})">
+ <template #text>
+ Test
+ </template>
+ </ButtonText>
+ <ButtonText @click="toast.add({ type: 'warning', title:'Default Toast Notification', description:'This is an example toast notification', life: 3000})">
+ <template #text>
+ Test
+ </template>
+ </ButtonText>
+ <ButtonText @click="toast.add({ type: 'info', title:'Default Toast Notification', life: 3000})">
+ <template #text>
+ Test
+ </template>
+ </ButtonText>
</div>
</div>
</div>