Skip to content

Commit

Permalink
Merge pull request 'Add import/export link lists' (#26) from 20240330…
Browse files Browse the repository at this point in the history
…-slides-nostr-check into main
  • Loading branch information
vicariousdrama committed Mar 31, 2024
2 parents c35a3d1 + e8cc1ac commit d00a4fd
Show file tree
Hide file tree
Showing 12 changed files with 453 additions and 51 deletions.
27 changes: 17 additions & 10 deletions pantry/nostr/nostr.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,14 @@ const getScheduledEvents = async () => {
if (eventTag[0] == 'starts' && eventTag[1].length > 0) {
try {
startTime = parseInt(eventTag[1]);
endTime = startTime + 3600; // just force to an hour length
endTime = startTime + (hourSeconds * 2); // assume 2 hour length
} catch(error) {
continue;
}
}
if (eventTag[0] == 'ends' && eventTag[1].length > 0) {
try {
endTime = parseInt(eventTag[1]);
} catch(error) {
continue;
}
Expand All @@ -257,12 +264,12 @@ const getScheduledEvents = async () => {
if (das.d == dTag) isDeleted = true;
}
if (isDeleted) {
//console.log('skipping activity that was deleted');
console.log(`skipping activity ${dTag} that was deleted`);
continue;
}
// Must have service tag
if (service == undefined) {
//console.log('skipping activity that has no service');
console.log(`skipping activity ${dTag} that has no service`);
continue;
}
// SPECIAL FIX FOR NOSTRNESTS: Set location if service is nostrnests
Expand Down Expand Up @@ -290,32 +297,32 @@ const getScheduledEvents = async () => {
}
// Reject based on erroneous time
if (startTime == undefined) {
//console.log('skipping event that has no start time');
console.log(`skipping event ${dTag} that has no start time`);
continue; // must have a time
}
if (endTime == undefined) {
//console.log('skipping event that has no end time');
console.log(`skipping event ${dTag} that has no end time`);
continue; // must have a time
}
if (startTime > endTime) {
//console.log('skipping event that starts after it ends');
console.log(`skipping event ${dTag} that starts after it ends`);
continue; // must begin before ending
}
if (endTime - startTime > daySeconds) {
//console.log('skipping event that lasts more than 1 day')
console.log(`skipping event ${dTag} that lasts more than 1 day`);
continue; // exclude events lasting more than 1 day
}
if ((startTime < timestamp) && (endTime + hourSeconds < timestamp)) {
//console.log('skipping event that has ended more than an hour ago');
console.log(`skipping event ${dTag} that has ended more than an hour ago`);
continue;
}
if (startTime > maxTime) {
//console.log('skipping event that starts more than a week from now');
console.log(`skipping event ${dTag} that starts more than a week from now`);
continue; // must start within 1 week
}
// check for required fields
if (!(title && location && startTime && endTime)) {
//console.log('skipping event that is missing one of title, location, startTime, endTime');
console.log(`skipping event ${dTag} that is missing one of title, location, startTime, endTime`);
continue;
}
console.log(`adding a matched event: ${title} (${location} starting ${startTime})`);
Expand Down
Binary file added ui/public/img/cornychat-links.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion ui/views/RoomSlides.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default function RoomSlides({
if (roomSlides && (sn > -1) && (sn < rsl)) {
let slideUrl = roomSlides[sn][0];
let slideText = roomSlides[sn][1];
let isImage = true;
let isImage = true; // assume its an image
let isVideo = false;
let isIFrame = false;
if (slideUrl.endsWith('.mp4')) {
Expand Down Expand Up @@ -74,6 +74,7 @@ export default function RoomSlides({
</div>
)}
<div className="text-sm flex-grow" style={{color: textColor, backgroundColor: colors.avatarBg}}>
[{(sn+1)}/{rsl}]
{slideText}
</div>
{(iOwn || iModerate) && (
Expand Down
57 changes: 56 additions & 1 deletion ui/views/Svg.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ export {
CopiedToClipboard,
Up,
Down,
First,
Previous,
Next,
Last,
GuyFawkes,
CoinStack,
};
Expand Down Expand Up @@ -548,7 +550,7 @@ function Down() {
);
}

function Previous({color}) {
function First({color}) {
return (
<svg
viewBox="0 0 24 24"
Expand All @@ -568,7 +570,60 @@ function Previous({color}) {
);
}

function Previous({color}) {
return (
<svg
fill="#000000"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
viewBox="0 0 490 490"
xml:space="preserve"
stroke="currentColor"
stroke-width="1.5"
class="w-5 h-5"
>
<g>
<g>
<g>
<path stroke={color} d="M245,490c135.1,0,245-109.9,245-245S380.1,0,245,0S0,109.9,0,245S109.9,490,245,490z M245,34.3
c116.2,0,210.7,94.5,210.7,210.7S361.2,455.7,245,455.7S34.3,361.2,34.3,245S128.8,34.3,245,34.3z"/>
<path stroke={color} d="M259.8,329.2c3.3,3.3,7.7,5,12.1,5s8.8-1.7,12.1-5c6.7-6.7,6.7-17.6,0-24.3l-60-60l60-60c6.7-6.7,6.7-17.6,0-24.3
s-17.6-6.7-24.3,0l-72.1,72.1c-3.2,3.2-5,7.6-5,12.1s1.8,8.9,5,12.1L259.8,329.2z"/>
</g>
</g>
</g>
</svg>
);
}

function Next({color}) {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
viewBox="0 0 512 512"
xml:space="preserve"
class="w-5 h-5"
stroke-width="1.5"
stroke="currentColor"
>
<g>
<g>
<g>
<path stroke={color} d="M256,0C114.618,0,0,114.618,0,256s114.618,256,256,256s256-114.618,256-256S397.382,0,256,0z M256,469.333
c-117.818,0-213.333-95.515-213.333-213.333S138.182,42.667,256,42.667S469.333,138.182,469.333,256S373.818,469.333,256,469.333
z"/>
<path stroke={color} d="M228.418,134.248c-8.331-8.331-21.839-8.331-30.17,0c-8.331,8.331-8.331,21.839,0,30.17L289.83,256l-91.582,91.582
c-8.331,8.331-8.331,21.839,0,30.17c8.331,8.331,21.839,8.331,30.17,0l106.667-106.667c8.331-8.331,8.331-21.839,0-30.17
L228.418,134.248z"/>
</g>
</g>
</g>
</svg>
);
}

function Last({color}) {
return (
<svg
viewBox="0 0 24 24"
Expand Down
1 change: 1 addition & 0 deletions ui/views/editRoom/EditRoom.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ export function EditRoomModal({roomId, iOwn, room, roomColor, close}) {
<div className="px-4 py-2 bg-gray-100 rounded-lg my-3">
<Links
iOwn={iOwn}
roomId={roomId}
roomLinks={roomLinks}
setRoomLinks={setRoomLinks}
textColor={textColor}
Expand Down
98 changes: 98 additions & 0 deletions ui/views/editRoom/ExportLinks.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import React, {useState} from 'react';
import {Modal} from '../Modal';
import {saveList} from '../../nostr/nostr';

export const ExportLinksModal = ({
close,
roomId,
textColor,
roomColor,
roomLinks,
}) => {
const dt = new Date();
const shortdate = dt.toISOString().replaceAll(':','-').replaceAll('T','.').replaceAll('-','').slice(0,13);
const [dTagValue, setDTagValue] = useState(`cornychat-${roomId}`);
const [name, setName] = useState('');
const [about, setAbout] = useState('');
const [displayError, setDisplayError] = useState(false);
const [errorMsg, setErrorMsg] = useState('');

async function saveit() {
let dTag = dTagValue;
if (dTag.length == 0) {
dTag = shortdate;
}
let imageUrl = jamConfig.urls.jam.replaceAll('/localhost/','/cornychat.com/') + '/img/cornychat-links.png';
let result = await saveList(dTag, name, about, imageUrl, 31388, roomLinks);
if (!result[0]) {
setErrorMsg(result[1]);
setDisplayError(true);
} else {
close();
alert('Link List published to relays');
return;
}
}

return (
<Modal close={close}>
<div className="bg-white p-6 rounded-lg">
<h2 className="text-2xl font-bold">Export Links</h2>
<p>
Unique ID
</p>
<div className="p-2 text-gray-500 italic">
{`Using the same ID of a prior export will overwrite it.`}
</div>
<input
type="text"
className="w-full p-2 border border-gray-300 mb-4"
placeholder="Unique ID (using the same of prior export will overwrite it)"
value={dTagValue}
onChange={e => {
setDTagValue(e.target.value);
}}
/>
<p>
Name
</p>
<input
type="text"
className="w-full p-2 border border-gray-300 mb-4"
placeholder="Name"
value={name}
onChange={e => {
setName(e.target.value);
}}
/>
<p>
About
</p>
<input
type="text"
className="w-full p-2 border border-gray-300 mb-4"
placeholder="About (optional)"
value={about}
onChange={e => {
setAbout(e.target.value);
}}
/>
<button
className="py-2 px-4 rounded text-center w-full"
style={{
backgroundColor: roomColor.buttons.primary,
color: textColor,
}}
onClick={async () => {
await saveit();
}}
>
Save
</button>
<div className="mt-5">
{displayError ? <p className="text-red-500">{errorMsg}</p> : null}
</div>
</div>
</Modal>
);
};
6 changes: 3 additions & 3 deletions ui/views/editRoom/ExportSlides.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const ExportSlidesModal = ({
}) => {
const dt = new Date();
const shortdate = dt.toISOString().replaceAll(':','-').replaceAll('T','.').replaceAll('-','').slice(0,13);
const [dTagValue, setDTagValue] = useState(`cornychat-${roomId}-${shortdate}`);
const [dTagValue, setDTagValue] = useState(`cornychat-${roomId}`);
const [name, setName] = useState('');
const [about, setAbout] = useState('');
const [slideUrl, setSlideUrl] = useState('');
Expand All @@ -21,15 +21,15 @@ export const ExportSlidesModal = ({
async function saveit() {
let dTag = dTagValue;
if (dTag.length == 0) {
dTag = dt.toISOString().replaceAll(':','-').replaceAll('T','.').replaceAll('-','').slice(0,13);
dTag = shortdate;
}
let result = await saveList(dTag, name, about, slideUrl, 30388, roomSlides);
if (!result[0]) {
setErrorMsg(result[1]);
setDisplayError(true);
} else {
close();
alert('Exported Slide Set published to relays');
alert('Slide List published to relays');
return;
}
}
Expand Down
Loading

0 comments on commit d00a4fd

Please sign in to comment.