Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement functionality of Filtering Existing Snippets by Language #93

Open
shivaypiece opened this issue Feb 23, 2024 · 1 comment
Open
Labels
good first issue Good for newcomers in the OSP Community.

Comments

@shivaypiece
Copy link
Contributor

shivaypiece commented Feb 23, 2024

The user should be able to see collections of snippets based on specific languages.

Solution:

You need to fetch the asset and then join it with its formats as well as any other metadata you want to fetch.

 const assets = await Promise.all(idArray.map(async (asset) => {
      const fetchedAsset = await this.Pieces.assetApi.assetSnapshot({
        asset,
        transferables: false, 
      });
      await this.mergeWithAnnotations(fetchedAsset);

Here we are merging assets with formats

const request = (format: string, retries = 0): Promise<Format | null> => {
    return Pieces.formatApi.formatSnapshot({ format, transferable: true }).catch(async () => {
      if (retries > 3) return null;
        await timeoutPromise(AssetFacade.RETRY_MS * Math.random());
          return request(format, retries += 1);
      });
  };

const queue = formatIds.map(ids => {
    
    // preview and original can be the same id
    // there is downstream changes from here if we only return one format
    // so I'm just returning the same promise twice if the ids are the same
    if (ids[0] === ids[1]) {
        const formatSnapshot = request(ids[0]);

        return Promise.all([formatSnapshot, formatSnapshot]).then(AssetsStorage.rehydrateAsset);
    }

return Promise.all(ids.map(request)).then(AssetsStorage.rehydrateAsset);
});
@shivaypiece shivaypiece added the good first issue Good for newcomers in the OSP Community. label Feb 23, 2024
@shivang-16
Copy link

hey @shivay-at-pieces , I want to work on this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers in the OSP Community.
Projects
None yet
Development

No branches or pull requests

2 participants