Newer
Older
My-Portfolio / frontend / src / components / utils / helpers.jsx
import {
  alltags,
  apps,
  game_systems,
  games,
  tag_icon,
  websites,
} from "../../assets";

// Filter projects based on selected tags
export const filterProjects = (projects, primaryTag, subtags) => {
  if (primaryTag === "All") return projects;

  return projects.filter((project) => {
    const matchesPrimaryTag = project.primaryTag === primaryTag;
    const matchesSubtags =
      subtags.length === 0 ||
      subtags.every((subtag) => project.subtags.includes(subtag));

    return matchesPrimaryTag && matchesSubtags;
  });
};

// Define tag hierarchy (primary tags and their subtags)
export const TAG_HIERARCHY = {
  All: {
    subtags: [],
    logo: alltags,
  },

  Games: {
    subtags: [
      "2D",
      "3D",
      "Unity",
      "Unreal Engine",
      "Singleplayer",
      "Multiplayer",
    ],
    logo: games,
  },

  "Game Systems": {
    subtags: [],
    logo: game_systems,
  },

  Websites: {
    subtags: [],
    logo: websites,
  },

  Apps: {
    subtags: [],
    logo: apps,
  },
};

// Helper to get a tag icon or default fallback
export const getTagIcon = (tag) => {
  const tagData = Object.entries(TAG_HIERARCHY).find(([key]) => key === tag);
  return tagData ? tagData[1].logo : tag_icon;
};