Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/fix/small-defects'
Browse files Browse the repository at this point in the history
  • Loading branch information
mh-zeynal committed Nov 29, 2023
2 parents c5b9856 + d9c6be2 commit 847f28c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions frontend/src/pages/workshops/WorkshopsPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export default function WorkshopsPage() {
level={item.level}
capacity={item.capacity}
cost={item.cost}
hasProject={item.has_project}
onClickAddToCart={() =>
addToCart({
id: item.id,
Expand Down
37 changes: 36 additions & 1 deletion frontend/src/pages/workshops/useWorkshopsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export default function useWorkshopsPage() {
useEffect(() => {
if (workshopsData == null || presentationsData == null || teachersData == null || presenterData == null) return;

const parsedData = workshopsData
let parsedData = workshopsData
.concat(presentationsData)
.map((workshop) => {
if ('is_full' in workshop && !('id' in workshop)) return null;
Expand Down Expand Up @@ -116,8 +116,43 @@ export default function useWorkshopsPage() {
return item;
})
.filter((e) => e != null);
parsedData.sort((a, b) => a.start_date > b.start_date ? 1 : -1)

const now = removeEverythingFromDateString(new Date().toLocaleString('fa-IR-u-nu-latn'))
let index = -1
console.log("now:", now)
for (const item of parsedData) {
const itemDate = removeEverythingFromDateString(new Date(item.start_date).toLocaleString('fa-IR-u-nu-latn'))
console.log(itemDate, now, itemDate > now)
index++
if (itemDate > now)
break
}

const notEligibleItems = parsedData.slice(0, index)
parsedData = parsedData.slice(index)
parsedData.push(...notEligibleItems)
console.log(parsedData)
console.log(index)
setParsedItemsList(parsedData);
setFileteredItems(parsedData);

function removeEverythingFromDateString(str) {
const splittedStr = str.split('/')
if (splittedStr[1].length === 1)
splittedStr[1] = '0' + splittedStr[1]
const secondSplittedStr = splittedStr[2].split(",")
if (secondSplittedStr[0].length === 1)
splittedStr[2] = "0" + secondSplittedStr.join(",")
str = splittedStr.join('/')
console.log(str)
return str
.replaceAll("/", '')
.replaceAll(" ", '')
.replaceAll(":", "")
.replaceAll(",", "")
}

}, [workshopsData, presentationsData, presenterData, teachersData]);

const addToCart = useCallback(
Expand Down

0 comments on commit 847f28c

Please sign in to comment.